我正在处理一个 C/C++ 项目,我正在使用 CMAKE 3.5.2 进行构建。但是,现在我必须包含一个使用 Octave 函数的 C++ 文件。我可以使用以下命令通过行命令直接编译此源文件:mkoctfile --link-stand-alone new_oct_file -o final_library
。
我正在努力让 CMAKE 执行此命令。我试过使用 add_custom_command
,但没有用。有人可以帮助我吗?
我的 CMAKE 具有以下结构
cmake_minimum_required(VERSION 2.8)
project(final_library)
add_executable(final_library program.c
./Commons/util.c
./Tools/xulambs_tool.cpp)
find_package(Boost REQUIRED)
include_directories(${Boost_INCLUDE_DIR})
include_directories(/usr/include/octave-4.0.0/octave)
install(TARGETS final-library RUNTIME DESTINATION bin)
add_subdirectory(Commons)
add_subdirectory(Tools)
我尝试添加以下命令(它不起作用):
set(MKOCTFILE "mkoctfile")
set(OCTARG "--link-stand-alone")
add_custom_command(TARGET reordering-library
PRE_LINK
COMMAND ${MKOCTFILE} ARGS ${OCTARG} ./Tools/tool_octave.cpp)
编译输出为
[ 4%] Linking CXX executable final-library
g++: error: ./Tools/tool_octave.cpp: No such file or directory
g++: fatal error: no input files
compilation terminated.
CMakeFiles/final-library.dir/build.make:694: recipe for target 'final-library' failed
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/final-library.dir/all' failed
Makefile:127: recipe for target 'all' failed
make[2]: *** [final-library] Error 1
make[1]: *** [CMakeFiles/final-library.dir/all] Error 2
make: *** [all] Error 2
谢谢。
最佳答案
我遇到了和你一样的问题,我通过在 CMakeLists.txt 文件的 target_link_libraries 中添加 liboctinterp.so 来修复它。
我当前的 cmake 文件包含以下内容:
add_executable(MyEXE main.cc) target_link_libraries(MyEXE liboctave.so liboctinterp.so)
关于c++ - CMAKE 和 MKOCTFILE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39355672/