What is the difference between

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?

Method 1

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"

Method 2

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


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 .

链接地址: http://www.djcxy.com/p/85786.html

上一篇: 之间有什么区别

下一篇: 有什么区别