Undefined character when compiled with -O2 on Mac only
I am working on a library that should compile on linux and mac os X. So far I have had no problems, compiling with "-g" worked well under both OSes.
I tried to compile some optimization ("-O2") and it works fine under Linux, but I get Undefined symbol when I try to link the program to my library under Mac OS X.
Does anyone know what I should be looking for?
nm mylib.a | grep _the_symbol
This returns the same for linux and mac (no underscore under linux):
154:00000018 C _the_symbol
377: U _the_symbol
Here is the linux compilation line for a program using the library:
/usr/bin/gcc -std=c99 CMakeFiles/prod-cons.dir/prod-cons.c.o -o prod-cons -rdynamic -L/home/claferri/dev/build/src ../src/libckaapi.a -lpthread -Wl,-rpath,/home/claferri/dev/build/src
And under mac:
/usr/bin/gcc -std=c99 -Wl,-search_paths_first -headerpad_max_install_names -fPIC CMakeFiles/prod-cons.dir/prod-cons.c.o -o prod-cons -L/Volumes/Data/claferri/Work/build/src ../src/libckaapi.a /usr/lib/libpthread.dylib
source to share
Note that the following is an assumption, and I can't say for sure if / until you provide the exact compiler flags you are using, but Xcode defaults to a value -fvisibility=hidden
that will almost completely hide the symbol in your library if it will not be declared visible.
You can do the same on Linux, but GCC does not hide symbols by default.
More information can be found here: http://gcc.gnu.org/wiki/Visibility