我想向 tensorflow 添加第三方 C 库,以便我可以在其中一个示例中使用它。似乎没有任何示例可以遵循,因此将不胜感激。
这是我使用 event2 作为第三方 C 库的工作。
我在 tensorflow/third_party 中创建了一个“ln -s”来提供 event2/ header :
ls -al ~/code/tensorflow/third_party/event2
lrwxr-xr-x 1 XXXX staff 25 May 17 16:03 ~/code/tensorflow/third_party/event2 -> /usr/local/include/event2
/usr/local/include> ls event2
BUILD bufferevent_struct.h event_compat.h listener.h thread.h
buffer.h dns.h event_struct.h rpc.h util.h
buffer_compat.h dns_compat.h http.h rpc_compat.h visibility.h
bufferevent.h dns_struct.h http_compat.h rpc_struct.h
bufferevent_compat.h event-config.h http_struct.h tag.h
bufferevent_ssl.h event.h keyvalq_struct.h tag_compat.h
第三方/事件2/构建:
licenses(["notice"])
cc_library(
name = "event2",
srcs = glob( [ "*.h" ] ),
visibility = [ "//visibility:public" ],
)
在 tensorflow/examples/label_image/BUILD 中,我添加了对 libevent 和使用 events2 库的测试文件的引用:
cc_binary(
name = "label_image",
srcs = [
"main.cc",
"my_new_file_using_events.c",
"my_new_file_using_events.h",
],
linkopts = ["-lm", ],
copts = [ "-Ithird_party", ],
deps = [
"//tensorflow/cc:cc_ops",
"//tensorflow/core:framework_internal",
"//tensorflow/core:tensorflow",
"//third_party/event2:event2",
],
)
它编译得很好,但是当我运行二进制文件时,出现以下错误:
dyld: lazy symbol binding failed: Symbol not found: _event_base_new
Referenced from: /Users/XXXX/code/tensorflow/bazel-bin/tensorflow/examples/label_image/label_image
Expected in: flat namespace
dyld: Symbol not found: _event_base_new
Referenced from: /Users/XXXX/code/tensorflow/bazel-bin/tensorflow/examples/label_image/label_image
Expected in: flat namespace
[1] 41395 trace trap bazel-bin/tensorflow/examples/label_image/label_image
libevent.a、libevent.dylib 和其他 libevent* 库位于/usr/local/lib 中。根据 nm,event_base 未定义。
nm -f label_image | grep event_base
U _event_base_dispatch
U _event_base_new
如何解决此链接错误?谢谢。
最佳答案
我们不是在那里缺少 event2 源吗?另外,我认为您想将 .h 放入 hdrs
属性中。
cc_library(
name = "event2",
hdrs = glob( [ "*.h" ] ),
srcs = glob( [ "*.cpp" ] ),
visibility = [ "//visibility:public" ],
)
这有帮助吗?
关于c++ - 如何将第 3 方 C 库添加到 tensorflow?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44075256/