c++ - 如何将第 3 方 C 库添加到 tensorflow?

标签 c++ tensorflow bazel

我想将第三方 C 库添加到 tensorflow,以便我可以在其中一个示例中使用它。似乎没有任何可遵循的示例,因此我们将不胜感激。

这是我使用 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

third_party/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

如何解决此链接错误?谢谢。

最佳答案

我们不是缺少 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/

相关文章:

python - tensorflow:在多个检查点上运行模型评估

bazel - 如何在 Bazel 中进行配置和变体处理?

c++ - 如何展平嵌套容器的迭代器?

java - 我应该如何选择在 C++ 中存储对象的位置?

tensorflow - Keras 中批量大小可变的batch_dot

java - 在 bazel 中导入 jar 时出现错误的魔法 efbfbdef 错误

bazel - 将子包中的文件组聚合到 bazel 中的大文件组中?

c++ - 我可以根据模板参数将某个值传递给成员构造函数吗?

c++ - 高频接收UDP包 : packet loss?

tensorflow - 强化学习算法的高效数据馈送