2017-04-05 51 views
0

Folk,Bazel Link .so庫位於完全不同的,非常遠程的文件夾中

我想鏈接.h和靜態庫到我的tensorflow程序中。我的頭是在

/usr/local/include/lcm 

而且靜態/共享庫(.so等)

/usr/local/lib 

但是巴澤爾抱怨他們不存在,或者說,它無法找到他們。這是我對我的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。 現在,我的非張量流代碼(或者我的大部分項目)正在運行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和巴澤爾工作

很抱歉的長期問題:-(

回答

1

巴澤爾在沙箱中執行操作(在你的情況下,C++編譯動作),以保證氣密性。這需要的是當動作變化的投入。因此,你必須告訴巴澤勒約所有的投入,包括系統的人改正。

但是,當然,你可以依靠系統庫,看看local_repository rule,你可能還會發現example in [email protected]線程有幫助

+0

我得到的錯誤: ERROR:/ home/mario/tensorflow_HY/tensorflow/tensorflow/examples/MYPROJECT/cpp/BUILD:39:1:沒有這樣的軟件包'@ lcm_headers //':加載軟件包'external'時出錯:名爲'lcm_headers'的軟件庫無法由'// tensorflow/examples/MYPROJECT/cpp:PROJECT'來解決和引用。 – Pototo

+0

參見上面的我的WOKSPACE和新的BUILD文件。在此先感謝您的幫助 – Pototo

+0

是否將工作區文件粘貼到回購的根目錄中?也許你有兩個工作區文件,一個在根目錄中,一個在tensorflow/examples/MYPROJECT /中。嘗試編輯根目錄。除此之外,它看起來確定.. – mhlopko

1

@mhlopko這裏是我的構建和工作區文件,位於同一目錄:

這是我碰到的工作區文件:

# 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", 
#) 
# 

我的BUILD:

# 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__"], 
) 
相關問題