How to deal with recursive dependencies between static libraries using the binutils linker?

a 夏天 提交于 2019-12-02 19:20:15
nos

Just do this:

g++ test_obj.o -lA -lB -lA       -o test

When the linker reads the first libA on the command line, it'll discard the object/symbols in it that noone has depended on yet, e.g. all the symbols libB needs but not test_obj.o. So you just make it read libA again, and it'll pick up the those symbols as well.

While @nos provides a simple solution, it doesn't scale when there are multiple libraries involved and the mutual dependencies are more complex. To sort out the problems ld provides --start-group archives --end-group.

In your particular case:

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