Reputation: 37075
I have a tiny C program called abc that uses dlopen internally to dynamically load and run a shared library libabc. libabc declares a function greeting that gets loaded and called dynamically at runtime. When I compile and run with the following two methods, the result works the same. What is the difference between -shared and -bundle flags on the GCC compiler when creating a shared object (.so) C library?
cc -c libabc.c -o libabc.o
cc **-shared** -o libabc.so libabc.o
cc -Wall -g abc.c -ldl -o abc
./abc ./libabc.so greeting "Hello World"
cc -c libabc.c -o libabc.o
cc **-bundle** -o libabc.so libabc.o
cc -Wall -g abc.c -ldl -o abc
./abc ./libabc.so greeting "Hello World"
Using Darwin gcc 4.2
Upvotes: 4
Views: 1349
Reputation: 51832
If you don't use -bundle
, the generated shared object can't be unloaded again with dlclose() after you dlopen() it; it will stay in memory for the whole lifetime of the process. -bundle
produces files of type MH_BUNDLE.
Btw, the recommended (but not mandatory) extension for bundles is .bundle
, not .so
.
Upvotes: 4