我已经编写了一个自定义OP,我想编写一个CMake文件以将该操作构建到库中。
这是我的CMake文件的样子:
cmake_minimum_required(VERSION 2.8)
message(STATUS "Make sure you have activated an environment with TensorFlow")
# get tensorflow include dirs, see https://www.tensorflow.org/how_tos/adding_an_op/
execute_process(COMMAND python -c "import tensorflow as tf; print(' '.join(tf.sysconfig.get_compile_flags()))" OUTPUT_VARIABLE TF_CFLAGS)
execute_process(COMMAND python -c "import tensorflow as tf; print(' '.join(tf.sysconfig.get_link_flags()))" OUTPUT_VARIABLE TF_LFLAGS)
# C++11 required for tensorflow
set(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
add_definitions(${TF_CFLAGS[]})
add_definitions(${TF_LFLAGS[]})
# build the actual TF operation
add_library(libname SHARED filename.cc)
当我尝试在Python中加载该函数时会生成操作,但出现以下错误:
undefined symbol: _ZTIN10tensorflow8OpKernelE
但是,如果我直接使用以下代码从命令行进行构建,则一切正常:
g++ -std=c++11 -shared ../color_balance.cc -o libcolor_balance.so -fPIC ${TF_CFLAGS[@]} ${TF_LFLAGS[@]} -O2
关于我的CMake文件中可能缺少什么的任何建议?