GCC 常用选项

来自艺搜天下
跳到导航 跳到搜索

编译动态库

-shared 还得结合-fPIC选项。-fPIC 选项作用于编译阶段,这样一来,产生的代码中就没有绝对地址了,全部使用相对地址,这正是共享库所要求的,共享库被加载时,在内存的位置不是固定的。

position independent code (PIC),Only position independent code is supposed to be included into shared objects (SO) as they should have an ability to dynamically change their location in RAM.

gcc -fPIC -shared func.c -o libfunc.so