I've just finished writing some C++ classes. I've written some test cases to test them and everything seems to be working fine, so I would like to compile the classes into a shared library (.so) so they can be shared. However, when I try to compile, I get the following error.
1 2 3 4 5 6
Undefined symbols:
"_main", referenced from:
start in crt1.10.5.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [lib] Error 1
This is the command that generated this error message.
I am working on Mac OS X. I thought I would try it on a Linux system (Fedora Core). I ran the same commands and the compiler told me to recompile with -fPIC flags. I did so and it was successful. However, I did the same thing back on my Mac and it still gives me the same errors. What could be causing this?
These commands were successful on Linux but not on Mac OS X.
OK, try compiling like this instead: g++ -Wall -dynamiclib -flat_namespace -Iinc <source files> -o <output dynamic library>.so
This seemed to work on Mac. For whatever reason, compiling libraries on Mac and on Linux seem to be very different, even if the compiler itself is the same.
I'll admit I'm no guru when it comes to C++, less so with C. Do you know of any references for gcc/g++ and their differences between OS X and Linux distros?