gpt4 book ai didi

c++ - Bazel Link .so 库位于一个完全不同的、非常远程的文件夹中

转载 作者:行者123 更新时间:2023-11-30 03:33:04 34 4
gpt4 key购买 nike

各位,

我正在尝试将 .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

这是我的构建文件和 WORKSPACE 文件,它们位于同一目录中:

这是我触摸的 WORKSPACE 文件:

# LCM static libraries
new_local_repository(
name = "lcm_libs",
# pkg-config --variable=libdir x11
path = "/usr/local/lib",
build_file_content = """
cc_library(
name = "liblcm",
srcs = ["liblcm.so"],
visibility = ["//visibility:public"],
)
""",
)

# LCM header files
new_local_repository(
name = "lcm_headers",
# pkg-config --variable=libdir x11
path = "/usr/local/include",
build_file_content = """
cc_library(
name = "lcm",
hdrs = glob([
"lcm/*.h", "lcm/*.hpp",
]),
visibility = ["//visibility:public"],
)
""",
)

# bind to a name to avoid using the "actual" format
#bind(
# name = "liblcm",
# actual = "@lcm_libs//:liblcm",
#)
#bind(
# name = "lcm",
# actual = "@lcm_headers//:lcm",
#)
#

还有我的构建:

# Description:
# Tensorflow C++ inference example for labeling images.

package(default_visibility = ["//tensorflow:internal"])
licenses(["notice"]) # Apache 2.0
exports_files(["LICENSE"])

cc_binary(
name = "facialFatigue",
srcs = [
"main.cc",
],
linkopts = ["-lm"],
deps = [
"//tensorflow/cc:cc_ops",
"//tensorflow/core:framework_internal",
"//tensorflow/core:tensorflow",
"@lcm_libs//:liblcm",
"@lcm_headers//:lcm",
],
)

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

抱歉这个问题太长了:-(

最佳答案

Bazel 在沙箱中执行操作(在您的例子中是 C++ 编译操作),以确保密封性。当 Action 的输入发生变化时,这需要是正确的。因此,您必须将所有输入告诉 Bazel,包括系统输入。

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

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

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com