g ++是否可以同一个库链接两次? [英] Can linking with the same library twice be a problem with g++?

查看:56
本文介绍了g ++是否可以同一个库链接两次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到,当我使用gcc创建应用程序并在链接阶段查看输出时,我看到以下lib包含了两次:

I noticed that when I make my application with gcc and look at the output during the linking phase, I see the following lib included twice:

/home/rb01/opt/trx-HEAD/gcc/4.2.4/lib/../lib64/libstdc ++.so

/home/rb01/opt/trx-HEAD/gcc/4.2.4/lib/../lib64/libstdc++.so

所以我只是想知道这是否是g ++(gcc)的问题,还是仅仅忽略了第二个问题?

And so I was just wondering if this is a problem with g++ (gcc) or if the second one is simply ignored?

谢谢!

推荐答案

如果库中的符号已经解析,则链接程序将忽略它们.在这种情况下,使用共享库,链接器实际上并不会链接.

If symbols in a library have already been resolved, the linker ignores them. With shared libraries, as in this case, the linker doesn't actually link anyway.

对于静态(.a)库,如果不是很漂亮,则命令行上的多个副本实际上是有用的,例如,如果main访问libb,而libc访问libc,而libc访问libb中的东西,而main却没有访问:

With static (.a) libraries, multiple copies on the command line can actually be useful, if not very pretty, if for example main accesses libb which accesses libc which accesses something in libb not accessed by main:

ld main.o -lb -lc -lb

是一种解决所有引用的方法.

is one way to get all the references resolved.

这篇关于g ++是否可以同一个库链接两次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆