Tuesday, 9 October 2007

Libraries and Mac OS X...

Ever wanted to build a shared library and hit a mac os x like machine, than the regular commandos:

$ gcc -c -fPIC calc_mean.c -o calc_mean.o
$ gcc -shared -Wl,-soname,libmean.so.1 -o libmean.so.1.0.1 calc_mean.o
will give you the error:
gcc -shared -Wl,-soname,libmean.so.1 -o libmean.so.1.0.1  calc_mean.o
i686-apple-darwin8-gcc-4.0.1: unrecognized option '-shared'
/usr/bin/ld: unknown flag: -soname
collect2: ld returned 1 exit status
You know why? Could those lovely things are called dynamic libraries in macworld and need the corresponding syntax ;-)

$ gcc -c -fPIC calc_mean.c -o calc_mean.o
$ gcc -dynamiclib -install_name libmean.dylib -o libmean.dylib calc_mean.o

Thanks to the example of René Nyffenegger about shared libraries in C

No comments:

Post a Comment