linking error: collect2 reports that /usr/bin/ld cannot find libraries.

779 views
Skip to first unread message

Leo Yin

unread,
Feb 23, 2016, 3:19:44 AM2/23/16
to bazel-discuss
Hi,

I tried to build gRPC with bazel and came across a linking error.

1) The following is a snippet from the BUILD I used.

cc_binary(                                                                                            
  name = "grpc_cpp_plugin",                                                                           
  srcs = [                                                                                            
    "src/compiler/cpp_plugin.cc",                                     
  ],                                                                                  
  linkopts=[                                                                     
    "-lprotoc -lprotobuf"                                                   
  ],                                                                                  
  deps = [                                                                       
    ":grpc_plugin_support",                                             
  ],                                                                                  
)    

2) libprotoc.a and libprotobuf.a have been installed in /usr/local/lib.

3) Target //:grpc_plugin_support has been build successfully.

4) Execute the build command "bazel build //:grpc_cpp_plugin --deleted_packages=third_party --subcommands" and I got the following error message:

...
>>>>> # //:grpc_cpp_plugin [action 'Linking grpc_cpp_plugin']
(cd /home/yinle/.cache/bazel/_bazel_yinle/efecb3aea10ca6e66c11c990034c4525/grpc-master && \
  exec env - \
  /usr/bin/gcc -o bazel-out/local_linux-fastbuild/bin/grpc_cpp_plugin -B/usr/bin/ -Wl,-z,relro,-z,now -no-canonical-prefixes -pass-exit-codes '-Wl,--build-id=md5' '-Wl,--hash-style=gnu' -Wl,-S -Wl,@bazel-out/local_linux-fastbuild/bin/grpc_cpp_plugin-2.params)
INFO: From Linking grpc_cpp_plugin:
/usr/bin/ld: cannot find -lprotoc
/usr/bin/ld: cannot find -lprotobuf
...

5) However, the command can be executed successfully if it is called in shell directly.

$ (cd /home/yinle/.cache/bazel/_bazel_yinle/efecb3aea10ca6e66c11c990034c4525/grpc-master && \
  exec env - \
  /usr/bin/gcc -o bazel-out/local_linux-fastbuild/bin/grpc_cpp_plugin -B/usr/bin/ -Wl,-z,relro,-z,now -no-canonical-prefixes -pass-exit-codes '-Wl,--build-id=md5' '-Wl,--hash-style=gnu' -Wl,-S -Wl,@bazel-out/local_linux-fastbuild/bin/grpc_cpp_plugin-2.params)
$ echo $?
0

Can someone give some help? 

Thank you very much.

-Leo



Brian Silverman

unread,
Feb 23, 2016, 1:42:43 PM2/23/16
to Leo Yin, bazel-discuss
Sounds like your problem is that the sandbox doesn't include anything in /usr/local. Building with --spawn_strategy=standalone --genrule_strategy=standalone is a quick workaround, but then you lose all the benefits of sandboxing.

A better solution is to create a new_local_repository(path = '/usr/local') in your WORKPACE. In the build file for that new repository, you should have a cc_library with each .a in its srcs that you can add to the deps of grpc_cpp_plugin. You will probably also need to set includes and hdrs on the cc_library to use the .h files from /usr/local.

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/b6d24052-fedf-4eb1-8d72-25a027ff8cb1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Leo Yin

unread,
Feb 24, 2016, 4:55:14 AM2/24/16
to bazel-discuss, leo...@huawei.com
Hi Brian,

The method of using new_local_repository() works. Thank you very much.


-Leo

在 2016年2月24日星期三 UTC+8上午2:42:43,Brian Silverman写道:
Reply all
Reply to author
Forward
0 new messages