Suppose there are three c files, say a.c
contains functions xx()
, yy()
and b.c
contains nn()
, mm()
and c.c
contains qq()
, rr()
.
假设有三个c文件,例如a.c包含函数xx(),yy()和b.c包含nn(),mm()和c.c包含qq(),rr()。
I made a static library stat.a
out of a.o
, b.o
and c.o
. If I link stat.a
into a test which calls xx()
, then symbol yy()
also gets exported: nm test
has both symbols xx
and yy
.
我从a.o,b.o和c.o中创建了一个静态库stat.a.如果我将stat.a链接到一个调用xx()的测试,那么符号yy()也会被导出:nm test同时包含符号xx和yy。
qq
and rr
do not get exported ?xx
being loaded?0
You have to inform the linker of your intention How to force gcc to link an unused static library
您必须通知链接器您的意图如何强制gcc链接未使用的静态库
gcc -L./ -o test test.c -Wl,--whole-archive stat.a -Wl,--no-whole-archive
gcc -L./ -o test test.c -Wl, - whole-archive stat.a -Wl, - no-whole-archive
From How do I include only used symbols when statically linking with gcc?
从静态链接到gcc时,如何仅包含已使用的符号?
gcc -ffunction-sections -c a.c
gcc -ffunction-sections -c a.c
gcc -L./ -o test test.c -Wl,--gc-sections stat.a
gcc -L./ -o test test.c -Wl, - gc-sections stat.a
本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2018/09/05/ac691d7fdcc3f2e7d9d280e66c04485.html。