Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #6256
| From | Ruben Safir <ruben@mrbrklyn.com> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: Linking Issue |
| Date | 2011-06-06 01:52 +0000 |
| Organization | PANIX Public Access Internet and UNIX, NYC |
| Message-ID | <ishbst$c1k$2@reader1.panix.com> (permalink) |
| References | <ish9ur$c1k$1@reader1.panix.com> |
http://www.nylxs.com/docs/quiz.tgz
On Mon, 06 Jun 2011 01:19:23 +0000, Ruben Safir wrote:
> I'm just not undertstanding what I'm doing wrong that the linker can't
> find my method function
>
> I have this header file
> questionss.h
>
>
> #ifndef QUESTION
> #define QUESTION
> #include <cstdlib>
> #include <cstdio>
> #include <string>
> #include <vector>
> #include <iostream>
> #include <iomanip>
> #include <termios.h>
>
> namespace Questions{
>
> class Question{
>
> public:
> Question(std::string q, std::string a): quest(q), answer(a){ }
> Question(){ }
> Question(Question const ©){
> this->quest = copy.quest;
> this->response = copy.response;
> this->answer = copy.answer;
> }
> std::string quest;
> std::string response;
> std::string answer;
>
>
>
>
>
>
>
> private:
>
>
>
> };
>
> class Deck{
>
> public:
> std::vector<Question> deck;
> Deck(){
> std::string home = std::getenv("HOME"); database = home +
> "/quiz.db";
> size = 0;
> }
>
>
>
> void get_stack();
> Question get_question();
> void give_quiz();
> void add_questions(Question &enter);
> void add_database();
> Question create_question(std::ostream &os = std::cout,
> std::istream &in = std::cin );
>
> private:
> int size;
> std::string database;
>
> };
>
>
> void menu(std::ostream &os = std::cout); void selection(Deck,
> std::istream &in = std::cin);
>
>
> } //end of namespace Question
>
>
> #endif
>
>
>
> this is a library file for questions ==> questions.cpp /*
> *
> =====================================================================================
> *
> * Filename: questions.cpp
> *
> * Description: Questions Class
> *
> * Version: 1.0
> * Created: 06/05/2011 07:08:05 PM * Revision: none
> * Compiler: gcc
> *
> * Author: Ruben Safir (), ruben@mrbrklyn.com * Company:
> NYLXS
> *
> *
> =====================================================================================
> */
>
> #include <cstdlib>
> #include <cstdio>
> #include <string>
> #include <vector>
> #include <iostream>
> #include <iomanip>
> #include <termios.h>
> #include "questions.h"
>
> namespace Questions{
>
> Question Deck::create_question(std::ostream &os , std::istream &in ){
> struct termios stored_settings;
> struct termios new_settings;
> std::string input_q, input_a;
> char keystroke;
>
>
> os << "Please Enter your question below \n Enter <esc> when
> finished" << std::endl; os <<
> "=================================================================="
> << std::endl;
>
> tcgetattr(0,&stored_settings);
>
> new_settings = stored_settings;
>
> /* Disable canonical mode, and set buffer size to 1 byte */
> new_settings.c_lflag &= (~ICANON);
> new_settings.c_cc[VTIME] = 0;
> new_settings.c_cc[VMIN] = 1;
>
> tcsetattr(0,TCSANOW,&new_settings);
>
> while( (keystroke = getchar()) ){
> if (keystroke == 27)
> break;
> input_q += keystroke;
> }
> os << "Please Enter your answer below \n Enter <esc> when
> finished" << std::endl; os <<
> "=================================================================="
> << std::endl;
>
> while( (keystroke = getchar()) ){
> if (keystroke == 27)
> break;
> input_a += keystroke;
> }
>
> Question quest(input_q, input_a);
>
>
>
>
> tcsetattr(0,TCSANOW,&stored_settings); return quest;
> }
>
> void menu(std::ostream &os){
> os << "Welcome the the C++ Quiz" << "\n\n\n\n" << std::endl;
> std::string tmp = " \n "
> "Select from one of the following: \n\n" "a) Insert Question and
> Answer into the database\n" "b) Read 25 Questions and run
> Quiz\n\n\nResponse==> ";
>
> os << tmp << std::endl;
>
> }
>
>
> void selection(Deck &stack, std::istream &is = std::cin) {
> char choice;
> Question tmp;
> if(is >> choice){
>
> switch ( choice ) {
> case 'a':
> tmp = stack.create_question();
> stack.add_questions(tmp);
> break;
>
> case 'b':
> break;
>
> default:
> break;
> } /* ----- end switch ----- */
> }
> }
>
> } /* End of Namespace Questions */
>
>
> And this is the main program
>
> #include <iostream>
> #include "questions.h"
> #include <string>
> #include <vector>
>
> int main(int argv, char *argc[]){
>
> Questions::Deck stack;
>
> Questions::menu();
> Questions::selection(stack);
>
> return 0;
> }
>
> and this is the makefile
> CXX:=g++
> CXXFLAGS:=-Wall -ggdb -pg
> LDFLAGS:= -pg
>
> quiz : quiz.o questions.o
> $(CXX) $(LDFLAGS) -o quiz quiz.o questions.o
>
> quiz.o : quiz.cpp questions.h
> $(CXX) $(LDFLAGS) -c quiz.cpp
>
> questions.o : questions.cpp questions.h
> $(CXX) $(LDFLAGS) -c questions.cpp
>
>
>
> include make.deps
> make.deps: *.cpp; ${CXX} ${CXXFLAGS} -M *.cpp >$@
>
>
>
>
> when I compile it I'm getting a linker error
>
>
> :!make 2>&1| tee /tmp/vo1mDhy/8
> g++ -pg -o quiz quiz.o questions.o
> quiz.o: In function `main':
> quiz.cpp:(.text+0x4b): undefined reference to
> `Questions::selection(Questions::Deck, std::basic_istream<char,
> std::char_traits<char> >&)' questions.o: In function
> `Questions::selection(Questions::Deck&, std::basic_istream<char,
> std::char_traits<char> >&)': questions.cpp:(.text+0x468): undefined
> reference to `Questions::Deck::add_questions(Questions::Question&)'
> collect2: ld returned 1 exit status
> make: *** [quiz] Error 1
> (1 of 7): g++ -pg -o quiz quiz.o questions.o
>
>
>
> The function is sitting there as plain as daylight
> class Deck{
>
> public:
> std::vector<Question> deck;
> Deck(){
> std::string home = std::getenv("HOME"); database = home +
> "/quiz.db";
> size = 0;
> }
>
>
>
> void get_stack();
> Question get_question();
> void give_quiz();
> void add_questions(Question &enter); <<==========
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Linking Issue Ruben Safir <ruben@mrbrklyn.com> - 2011-06-06 01:19 +0000
Re: Linking Issue "Paul" <pchristor@yahoo.co.uk> - 2011-06-06 02:51 +0100
Re: Linking Issue red floyd <redfloyd@gmail.com> - 2011-06-06 10:16 -0700
Re: Linking Issue "Paul" <pchristor@yahoo.co.uk> - 2011-06-06 20:22 +0100
Re: Linking Issue Joshua Maurice <joshuamaurice@gmail.com> - 2011-06-06 14:06 -0700
Re: Linking Issue Ruben Safir <ruben@mrbrklyn.com> - 2011-06-06 01:52 +0000
Re: Linking Issue Joshua Maurice <joshuamaurice@gmail.com> - 2011-06-05 19:01 -0700
Re: Linking Issue Ruben Safir <ruben@mrbrklyn.com> - 2011-06-06 02:18 +0000
Re: Linking Issue "Paul" <pchristor@yahoo.co.uk> - 2011-06-06 03:24 +0100
Re: Linking Issue red floyd <redfloyd@gmail.com> - 2011-06-06 10:18 -0700
Re: Linking Issue ruben safir <ruben@mrbrklyn.com> - 2011-06-06 14:41 -0400
Re: Linking Issue Paavo Helde <myfirstname@osa.pri.ee> - 2011-06-06 16:21 -0500
csiph-web