简体   繁体   English

如何强制gcc链接静态库?

[英]how can i force gcc to link a static library?

I write a static library: libA.a. 我写了一个静态库:libA.a。 I have another application called BoBo doesn't used any functions in libA.a. 我有另一个名为BoBo的应用程序,它在libA.a中未使用任何功能。 I want to combine libA.o into Bo, then I could call some stuff in libA.a by other methods, when Bo is running. 我想将libA.o合并到Bo中,然后在Bo运行时可以通过其他方法在libA.a中调用一些东西。

I write makefile like this: gcc Bc -o Bo -lA -u symbol_A . 我这样写makefile: gcc Bc -o Bo -lA -u symbol_A Here -u is from GCC manual: 这里-u来自GCC手册:

http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html

It suggests use -u to force linking unused library, and symbol_A is some symbol in libA.a 它建议使用-u强制链接未使用的库,并且symbol_A是libA.a中的某些符号。

But it doesn't work. 但这是行不通的。 After linking, I can not find any LibA.a's stuff in Bo 链接后,我在Bo中找不到任何LibA.a的东西

May anyone give me some hint? 谁能给我一些提示吗?

ps I am using GCC 3.4.4, eclipse+CDT under windows, and Bo will be deployed under linux. ps我使用的是GCC 3.4.4,在Windows下使用eclipse + CDT,而Bo将在Linux下部署。

The explanation of the -u flag from GCC means the following: 来自GCC的-u标志的解释含义如下:

If you have a symbol aka variable or function that is defined in your source tell GCC to pretend that it is undefined so it takes the definition of such variable or function from the library you are linking. 如果您在源代码中定义了符号aka变量或函数,请告诉GCC假装它未定义,因此它将从您链接的库中获取此类变量或函数的定义。

So if your Bc has nothing that may be defined in libA.a the -u flag won't help you since the symbol_A is not needed by Bc and by the same token Bo , so will be simply ignored. 因此,如果您的Bc没有在libA.a定义的libA.a-u标志将无济于事,因为Bc和相同的令牌Bo不需要symbol_A ,因此将被忽略。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM