Bazel failed to include a external static library .a

て烟熏妆下的殇ゞ 提交于 2019-12-10 11:38:38

问题


-- Question solved --

This question is solved. Thanks for all the help!

The problem and the reason is briefly stated as following for other readers in the future:

[Environment]

Ubuntu 14.04, Bazel, C++

[Question]

I want to include an external library. So I download the source file and make it as as a static lib .a.

I correctly set the BUILD, WORKSPACE and related files. However, when compile, it alerts the error:

Linking of rule '//main' failed (Exit 1)
main: error: undefined reference to 'void ex_lib::compute(double*, double const*, double const*)'
collect2: error: ld returned 1 exit status

I tried with the .lo and alwayslink method here but doesn't work.

Alternate to "`--whole-archive`" in bazel

[Reason]

It is because that the external library source files contains duplicate header files. So I fix the header file problem. Make the .a again. Then everything works.

So nothing wrong with the bazel. It is the library itself that cause the problem. But the error information is confusing and I think it is caused by bazel.


回答1:


What you can do to investigate further is to run the clean bazel build with --subcommands to see individual command lines of actions executed. Then you can cd into the sandbox, and execute the same gcc command as bazel does and debug what's wrong. Or you can try to get linking to work by handwriting gcc command, and pasting here both the command bazel generated, and your desired command. Is it possible that you have multiple liegroups libs installed on the system and gcc is getting one that's incompatible with headers you're including?




回答2:


The problem is solved. Special thanks to mhlopko.

It is mainly because there is errors with the lib source file. Thus .a file I use contains errors. Now the bazel works fine with the new lib file.

By the way, now bazel works fine with both .a or .so file that I generated.



来源:https://stackoverflow.com/questions/47643710/bazel-failed-to-include-a-external-static-library-a

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