首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

gcc中_attribute_ ((constructor(101)))做成.a库顺利链接

2013-09-07 
gcc中__attribute__ ((constructor(101)))做成.a库成功链接1.cpp:--------------------------------------

gcc中__attribute__ ((constructor(101)))做成.a库成功链接

1.cpp:------------------------------------------------
#include

int test() __attribute__ ((constructor(101)));

int test()
{
printf("\n--In lib--");
return 0;
}

test.cpp //没有call 1.cpp中方法,但是希望在main前面先执行test()函数
#include

int main()
{
printf("\n---In main--");
return 0;
}


g++ -c 1.cpp //生成1.o
ar -rcs libanti.a 1.o //生成.a库
g++ test.cpp -Wl,--whole-archive libanti.a -Wl,--no-whole-archive -o main //libanti.a必须全名,不能用-lanti,否则不成功

热点排行