民间,

我正在尝试将.h和静态库链接到我的tensorflow程序中。我的标题在

/usr/local/include/lcm

和静态/共享库(.so等)中
/usr/local/lib

但是Bazel抱怨说它们不存在,或者找不到它们。这是我的BUILD文件中的代码:
package(default_visibility = ["//tensorflow:internal"])
licenses(["notice"])  # Apache 2.0
exports_files(["LICENSE"])

# LCM shared libraries path
cc_library(
    name = "lcm_lib",
    srcs = glob([
        "*.so",
    ]),
    copts = ["-L/usr/local/lib"],
    linkopts = ["-pthread", "-shared"],
    visibility = ["//visibility:public"],
)

# LCM header libraries path
cc_library(
    name = "lcm_headers",
    hdrs = glob([
        "include/**/*.h",
    ]),
    copts = ["-L/usr/local/include"],
    linkopts = ["-pthread"],
    visibility = ["//visibility:public"],
)

cc_binary(
    name = "myProject",
    srcs = [
        "main.cc",
    ],
    linkopts = ["-lm"],
    deps = [
        "//tensorflow/cc:cc_ops",
        "//tensorflow/core:framework_internal",
        "//tensorflow/core:tensorflow",
    ],
)

filegroup(
    name = "all_files",
    srcs = glob(
        ["**/*"],
        exclude = [
            "**/METADATA",
            "**/OWNERS",
            "bin/**",
            "gen/**",
        ],
    ),
    visibility = ["//tensorflow:__subpackages__"],
)

如果我删除了与LCM相关的代码(从BUILD和main.cc中都删除了),则我的程序将生成并运行。当我包含LCM时,我会收到错误消息,指出lcm::LCM::〜LCM()是未定义的,并且找不到liblcm.so。
现在,我的非tensorflow代码(或项目的大部分内容)正在运行cmake,并且可以找到LCM和我需要的其余库(openCV等)。我在CMakeList.txt中使用命令,例如:
# search path for LCM header files
set(LCM_IncludeSearchPaths
  /usr/include/
  /usr/local/include/
  /opt/local/include
)
# search path for LCM static/dynamic libraries
set(LCM_LibrarySearchPaths
  /usr/lib/
  /usr/local/lib/
  /opt/local/lib/
)
find_path(LCM_INCLUDE_DIR
    NAMES lcm/lcm.h
    HINTS ${LCM_IncludeSearchPaths}
)
FIND_LIBRARY(LCM_LIBS
  NAMES lcm
  HINTS ${LCM_LibrarySearchPaths}
  PATH_SUFFIXES lib
)

而且一切正常。但是它不适用于 tensorflow 和Bazel

很抱歉这个长问题:-(

最佳答案

Bazel在沙箱中执行操作(在您的情况下为C++编译操作),以确保密封性。当 Action 的输入发生更改时,这是正确的。因此,您必须告诉Bazel有关的所有输入,包括系统的输入。

但是当然您可以依赖系统库,看看local_repository rule。您可能还会发现example in bazel-discuss@线程很有帮助。

关于c++ - Bazel Link .so库位于完全不同的非常远程的文件夹中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43220067/

10-12 22:07