我想将一个第三方C库添加到TensorFlow中,以便我可以在其中一个示例中使用它。目前没有可供参考的示例,因此需要任何帮助。
以下是我使用event2作为第三方C库的工作。
我在tensorflow/third_party中创建了一个“ln -s”来提供event2/头文件:
在tensorflow/examples/label_image/BUILD文件中,我添加了对libevent和使用events2库的测试文件的引用:
我该如何解决这个链接错误?谢谢。
以下是我使用event2作为第三方C库的工作。
我在tensorflow/third_party中创建了一个“ln -s”来提供event2/头文件:
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
第三方/event2/BUILD:
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
我该如何解决这个链接错误?谢谢。