Use pre-compiled third party library as a cc_library

1,722 views
Skip to first unread message

Liang Zou

unread,
Nov 30, 2016, 2:45:52 PM11/30/16
to bazel-discuss
Hi,
I want to use pre-compiled third party library as a cc_library rule so that my binary can depend on it.
I'm using Mac, so I installed the library with "brew install gflags". Then I created a BUILD file for the library:
package(default_visibility = ["//visibility:public"])

cc_library(
    name = "gflags",
    srcs = [
      "lib/libgflags.dylib",
    ],
    hdrs = glob(["include/**/*.h"]),
    includes = ["include"],
)

The binary can be built, but when it runs, I got the exception: 

dyld: Library not loaded: /usr/local/opt/gflags/lib/libgflags.2.2.dylib

  Referenced from: /Users/liangzou/gitreview/bazel-bin/tools/viewer/omap_viewer

  Reason: image not found


I don't think I'm using the pre-compiled dynamic library correctly. Can someone please point out what the problem is? Thanks a lot in advance.

Paul Johnston

unread,
Nov 30, 2016, 3:20:19 PM11/30/16
to bazel-discuss
Just use it as an external dependency, no need to involve homebrew.

Liang Zou

unread,
Nov 30, 2016, 3:53:44 PM11/30/16
to bazel-discuss
Thank you for your reply, Paul.
I'm just using gflags as an example. I just want to know in general, how to use pre-compiled libraries from homebrew as an dependency. Or is it possible?

Paul Johnston

unread,
Nov 30, 2016, 4:57:16 PM11/30/16
to bazel-discuss

Liang Zou

unread,
Nov 30, 2016, 8:34:51 PM11/30/16
to bazel-discuss
I don't want to use local_repository because other coworkers will need to install the library.
What I want is a http_repository, so I can upload the pre-compiled libraries to a server.

Unfortunately, my question is still unsolved.

xiongc...@gmail.com

unread,
Aug 8, 2019, 9:15:24 PM8/8/19
to bazel-discuss
if my lib is not a bazel project,i haved compiled its dynamic library,how do I use this library

在 2016年12月1日星期四 UTC+8上午4:20:19,Paul Johnston写道:

László Csomor

unread,
Aug 9, 2019, 2:55:25 AM8/9/19
to xiongc...@gmail.com, bazel-discuss
https://docs.bazel.build/versions/master/be/c-cpp.html#cc_import


--
László Csomor | Software Engineer | laszlo...@google.com

Google Germany GmbH | Erika-Mann-Str. 33 | 80636 München | Germany
Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg
Geschäftsführer: Paul Manicle, Halimah DeLaine Prado
> --
> 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/eb1506aa-e2e3-4987-aa83-f8f5c36c0011%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages