Search code examples
includestatic-librariesbazel

Bazel failed to include a external static library .a


-- 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.


Solution

  • 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.