Can linking with the same library twice be a problem with g++?

蓝咒 提交于 2019-12-23 14:19:14

问题


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

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

Thanks!


回答1:


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.

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.



来源:https://stackoverflow.com/questions/2282486/can-linking-with-the-same-library-twice-be-a-problem-with-g

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!