要在Linux上创建一个共享对象(.so)文件,而不使用-fPIC标志,可以按照以下步骤进行:
#include
void hello() {
printf("Hello, World!\n");
}
gcc -c test.c -o test.o
SECTIONS
{
. = 0x0;
.text : { *(.text) }
.data : { *(.data) }
.bss : { *(.bss) }
}
gcc -shared -Wl,--version-script=test.ld test.o -o libtest.so
在上述命令中,-shared标志告诉gcc生成共享对象,-Wl,--version-script=test.ld指定链接脚本文件,test.o是目标文件的文件名,libtest.so是生成的共享对象文件的文件名。
现在,您应该有一个名为libtest.so的共享对象文件,可以在其他程序中使用它。