Undefined Symbols

I'm trying to create a linked list but I get that error always. I separated it into .hpp and .cpp files, and thats where the problem lives I guess, the error I get when I compile the archive list.cpp (implementation of its methods) looks like this:

Undefined symbols for architecture x86_64:
  "Node::Node(int)", referenced from:
      List::insert(int) in list-6224f1.o
      List::insertEnd(int) in list-6224f1.o
      List::insertHead(int) in list-6224f1.o
      List::insertIntoPos(int, int) in list-6224f1.o
  "_main", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)


But when I compile using "-c" parameter it works
g++ -Wall -Wconversion -c list.cpp

Last edited on
If you split your program into files a.cpp, b.cpp, ..., z.cpp then you have to compile all of them.

Option 1:
g++ [options] a.cpp b.cpp ... z.cpp

Option 2:
g++ [options] -c a.cpp -o a.o
g++ [options] -c b.cpp -o b.o
...
g++ [options] -c z.cpp -o z.o
g++ a.o b.o ... z.o -o executable
Last edited on
Alright it worked fine now. Thanks!
More specifically, you have to:
- compile each source code file to an object file
- link all the object files into an executable
Topic archived. No new replies allowed.