Alternate to “`--whole-archive`” in bazel

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 01:06:19

问题


I want to link an external static lib in one of my bazel based c++ project. I need "whole-archive" option for linking the library like gcc or g++ build:

g++ main.cc -Wl,--whole-archive -lhttp -Wl,--no-whole-archive

Can anybody suggest what is the alternate to "--whole-archive" in bazel?


回答1:


Sadly, alwayslink doesn't work with precompiled libraries, only with cc_library compiled and linked by Bazel. There is one undocumented hack (I guess I'm just documenting it by mentioning it here), and it's to rename .a file to .lo file. Then Bazel will link it as whole archive.

Beware that this is a hack, and will stop working without warning. We have plans for some variation of cc_import rule exactly for this use case, to import a precompiled binary into the workspace with the ability to set whole archiveness on it. It's just not there yet.




回答2:


https://bazel.build/versions/master/docs/be/c-cpp.html#cc_library.alwayslink

alwayslink

Boolean; optional; nonconfigurable; default is 0

If 1, any binary that depends (directly or indirectly) on this C++ library will link in all the object files for the files listed in srcs, even if some contain no symbols referenced by the binary. This is useful if your code isn't explicitly called by code in the binary, e.g., if your code registers to receive some callback provided by some service.



来源:https://stackoverflow.com/questions/44674163/alternate-to-whole-archive-in-bazel

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