Undefined symbols for architecture x86_64

Nov 21, 2011 at 1:20am
I am trying to write a program that can simulate a flowchart.
A flowchart is made of "cells", which are connected by "yes"/"no".
I divide cells into to types "Link" and "End", where Link cells connect to other cells when answered, and End cells output a final message before exiting.

However, when I try to compile, I get:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Undefined symbols for architecture x86_64:
  "vtable for Cell", referenced from:
      Cell::~Cell() in ccd04F6O.o
      Cell::~Cell() in ccd04F6O.o
      Cell::Cell(Cell const&)in ccd04F6O.o
  "Cell::flow()", referenced from:
      LinkCell::flow()     in ccd04F6O.o
  "Cell::Cell()", referenced from:
      EndCell::EndCell(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >)in ccd04F6O.o
      EndCell::EndCell(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >)in ccd04F6O.o
      LinkCell::LinkCell(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Cell, Cell)in ccd04F6O.o
      LinkCell::LinkCell(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Cell, Cell)in ccd04F6O.o
  "Cell::Cell()", referenced from:
      LinkCell::LinkCell(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Cell, Cell)in ccd04F6O.o
      LinkCell::LinkCell(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Cell, Cell)in ccd04F6O.o
  "typeinfo for Cell", referenced from:
      typeinfo for LinkCellin ccd04F6O.o
      typeinfo for EndCellin ccd04F6O.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status


And here is my source code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <iostream>
#include <string>

using namespace std;
        
class Cell {
   protected:
        string query;
	string val;
   public:
	Cell();
        void setVal();
        string getVal() {return val;}
        string getQuery() {return query;}
        virtual void flow();
   };
 
void Cell::setVal(){
      cout << getQuery() << " [y/n] ";
      cin >> val;
      if ((getVal()!="y") && (getVal()!="n")){
         while ((getVal()!="y")&&(getVal()!="n")){
            cout << "Please enter y or n: ";
            cin >> val;
         }
      }
}

class LinkCell: public Cell {
	Cell yQuery;
	Cell nQuery;
   public:
	LinkCell(string,Cell,Cell);
	void flow();
};

LinkCell::LinkCell (string setQuery, Cell yLink, Cell nLink) {
	query = setQuery;
	yQuery = yLink;
	nQuery = nLink;
}

void LinkCell::flow(){
	setVal();
        if (getVal()=="y"){yQuery.flow();}
        if (getVal()=="n"){nQuery.flow();}
}

class EndCell: public Cell {
	string yEnd;
	string nEnd;
   public:
	EndCell(string,string,string);
    void flow();
};

EndCell::EndCell (string setQuery, string yMessage, string nMessage){
	query = setQuery;
	yEnd = yMessage;
	nEnd = nMessage;
}


void EndCell::flow(){
	setVal();
    if (getVal()=="y"){cout << yEnd;}
    if (getVal()=="n"){cout << nEnd;}
}

int main(){

	EndCell sorry("Do you want me to feel sorry for you?","I'm sorry for you","I'm not sorry for you");
	EndCell happy("Do you want me to feel happy for you?","I'm happy for you","I'm not happy for you");
	LinkCell ok("Are you ok?", happy, sorry);

	ok.flow();

return 0;
}


main() is just a usage example for the class structure.

Thanks, hope to get some answers soon (this is work for a project).
Nov 21, 2011 at 1:28am
Undefined Symbols generally indicates a linking issue. Are you definitely linking correctly to the appropriate library?

Edit: To expand, your code compiles fine. The linker then goes looking in the libraries for the right functions, and since you compiled for architecture x86_64, it looks for the right libraries, similarly compiled - and finds none. This suggests (unless you've simply forgotten to link to the 64 bit library)at you've got a 32 bit version of the library. Your choices are:

1) Build your code for 32 bit, so you can use the libraries you've got.
2) Get the library source code, and compile it yourself for x86_64
3) Go looking wherever you found the library, and hope there's an x86_64 version sitting next to the 32 bit version you found last time.
Last edited on Nov 21, 2011 at 1:38am
Nov 21, 2011 at 1:38am
I'm not quite sure what linking to a library is (still at a beginner-ish level). But, if you mean linking at compilation, then I can say that this is the only file in my project.

Thanks for the reply...
Nov 21, 2011 at 1:41am
if you mean linking at compilation,


No no no, linking and compilation are completely different things. You compile, and then when that's all finished, you link. You can stop after compiling if you like. That's how a library is made - just compiled, not linked.

Possibly I'm over-thinking this. If this is all your code, and you're not using a library, then the problem is simple. You simply haven't written all the functions yet. You need to write the following functions:

Cell::Cell()
Cell::flow()

The linker is complaining because you've not provided them, and it's the job of the linker to make sure that every function you ever call actually has been written and compiled.
Last edited on Nov 21, 2011 at 1:43am
Nov 21, 2011 at 2:11am
Thanks, that worked. I simply removed Cell::Cell() (I didn't need it)
and then defined Cell::flow(){}

It compiles now.
Still on run, it stops after asking "Are you okay?" and getting an answer, instead of going on to ask either the "yQuery" of "nQuery".

Edit:

I started debugging, and realized where the problem is.
When yQuery.flow() (or nQuery.flow() )
is called from a LinkCell's flow function, it tries to access the generic Cell.flow() instead of the flow of the subclass yQuery or nQuery belongs to.

For those interested, here are the code and result:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <iostream>
#include <string>

using namespace std;
        
class Cell {
   protected:
        string query;
	string val;
   public:
        void setVal();
        string getVal() {return val;}
        string getQuery() {return query;}
    virtual void flow(){cout << "*** Error: accessed Cell.flow() \n";};
   };
 
void Cell::setVal(){
      cout << getQuery() << " [y/n] ";
      cin >> val;
      if ((getVal()!="y") && (getVal()!="n")){
         while ((getVal()!="y")&&(getVal()!="n")){
            cout << "Please enter y or n: ";
            cin >> val;
         }
      }
}

class LinkCell: public Cell {
	Cell yQuery;
	Cell nQuery;
   public:
	LinkCell(string,Cell,Cell);
	void flow();
};

LinkCell::LinkCell (string setQuery, Cell yLink, Cell nLink) {
	query = setQuery;
	yQuery = yLink;
	nQuery = nLink;
}

void LinkCell::flow(){
	cout << "--> Reached setVal for LinkCell " << getQuery() << endl; setVal();
        if (getVal()=="y"){cout << "==> Reached getVal=y : atttemping to execute yQuery '" << yQuery.getQuery() << "'" << endl; yQuery.flow();}
        if (getVal()=="n"){cout << "==> Reached getVal=n : atttemping to execute nQuery '" << nQuery.getQuery() << "'" << endl; nQuery.flow();}
}

class EndCell: public Cell {
	string yEnd;
	string nEnd;
   public:
	EndCell(string,string,string);
    void flow();
};

EndCell::EndCell (string setQuery, string yMessage, string nMessage){
	query = setQuery;
	yEnd = yMessage;
	nEnd = nMessage;
}


void EndCell::flow(){
	setVal();
    if (getVal()=="y"){cout << yEnd << endl;}
    if (getVal()=="n"){cout << nEnd << endl;}
}

int main(){

	EndCell sorry("Do you want me to feel sorry for you?","I'm sorry for you","I'm not sorry for you");
	EndCell happy("Do you want me to feel happy for you?","I'm happy for you","I'm not happy for you");
	EndCell work("Do you want to work now?","Let's do it!","Let's hang out");
	LinkCell help("Can I help you?",work,sorry);
	LinkCell ok("Are you ok?",happy,help);

	ok.flow();

return 0;
}


1
2
3
4
--> Reached setVal for LinkCell Are you ok?
Are you ok? [y/n] y
==> Reached getVal=y : atttemping to execute yQuery 'Do you want me to feel happy for you?'
*** Error: accessed Cell.flow()


Is there a way to access the flow function specific to yQuery/nQuery 's subtype?
Last edited on Nov 21, 2011 at 2:42am
Topic archived. No new replies allowed.