c++ - Can compile in Ubuntu but not in Mac OS X -


i built dynamic library (.so file) on ubuntu 12.04. let's call test.so. had test.cpp file, calls library functions. first compiled test.cpp test.o by:

g++ test.cpp -o -c test.o 

it succeeded. compiled test.o test.so by:

g++ -shared test.o -o test.so 

also succeeded.

i did similar thing on mac os x.

i first got test.o by:

g++ test.cpp -o -c test.o 

then

g++ -dynamiclib test.o -o test.dylib 

this failed, because didn't provide libraries used in test.cpp. modified it:

g++ -dynamiclib test.o -o test.dylib -l/path/to/libraries -llibraryname 

then works.

notice first case, didn't provide such path libraries , specific library used in test.cpp. know why don't need in first case need in second case?

the linker, default options, not behave same on linux , osx. osx linking behave more expect on linux, use following link flag.

-wl,-undefined,dynamic_lookup 

Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -