链接路径混淆target_link_libraries调用后 [英] link path confusion after target_link_libraries call
问题描述
我有一个cmake项目,我想添加一个包含matlab引擎的类。为了编译它,我需要包含两个库 eng
和 mx
,我通过添加
target_link_libraries($ {TARGET} /usr/local/MATLAB/R2013b/bin/glnxa64/libeng.so)
target_link_libraries($ {TARGET} /usr/local/MATLAB/R2013b/bin/glnxa64/libmx.so)
添加到我的 CMakeLists.txt
文件中。
然而, / usr中还有许多其他旧版本的库/ local / MATLAB / R2013b / bin / glnxa64 /
,当调用上述命令时,似乎
自动添加到路径中。我认为这会导致编译器无法再找到我的
正常库并产生一个错误。
如何仅包含上述两个库,而不包含<$ c $中的所有其他库c> glnxa64 文件夹?
运行 cmake 。
:
CMakeLists.txt中的CMake警告:23(add_executable):
Can not为目标CCDWidget生成安全的运行时搜索路径,因为某些目录中的
文件可能与隐式
目录中的库冲突:
运行时库[libboost_program_options.so.1.49.0]中的/ usr / lib可能被以下文件隐藏:
/ usr / local / MATLAB / R2013b / bin / glnxa64
/ usr / lib中的运行时库[libboost_system.so.1.49.0]可能隐藏在/ usr / lib中的
/ usr / local / MATLAB / R2013b / bin / glnxa64
运行时库[libboost_filesystem.so.1.49.0]中的文件可能被以下文件隐藏:
/ usr / local / MATLAB / R2013b / bin / glnxa64
运行时库[l / usr / lib中的ibboost_regex.so.1.49.0]可能被以下文件隐藏:
/ usr / local / MATLAB / R2013b / bin / glnxa64
这些库中的一些可能不会被发现正确。
链接期间的错误消息:
<$ $ CX $可执行文件CCDWidget
/usr/lib/x86_64-linux-gnu/libharfbuzz.so.0:对'FT_Face_GetCharVariantIndex'的未定义引用
/ usr / lib / x86_64-linux-gnu / libharfbuzz.so.0:对'FT_Get_Advance'的未定义引用
collect2:错误:ld返回1退出状态
make [2]:*** [CCDWidget]错误1
make [1]:*** [CMakeFiles / CCDWidget.dir / all]错误2
make:*** [all]错误2
下面是我完整的 CMakeLists.txt
文件。两行注释掉##是我以前尝试过的替代方法,并没有解决我的问题。
我还在target_link_libraries命令中添加了 LINK_PRIVATE
,如下面的代码所示,这没有什么区别。
单独的选项 PRIVATE
似乎不被我的cmake版本所接受,因为它将错误消息更改为
/ usr / bin / ld:找不到-lPRIVATE
collect2:错误:ld返回1退出状态
当 #eng
行被注释掉时,编译和链接可以正常工作
(when调用matlab引擎也在 Readout.cpp
中注释掉),所以错误必须由该行产生。
< hr>
#指定使用的版本以及语言
cmake_minimum_required(VERSION 2.6)
## cmake_policy SET CMP0003 NEW)
#在这里命名您的项目
项目(CCDWidget)
set(TARGET CCDWidget)
set(MAIN_SOURCES CCDWidget.cpp main.cc CCDControl.cpp VideoWindow.cpp ImageWindow.cpp ThisMeasurement.cpp KineticSeries.cpp FastKinetics.cpp Readout.cpp)
## SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
$ b $ #set_source_files_properties(Readout.cpp PROPERTIES COMPILE_FLAGS-I / usr / local / MATLAB / R2013b / extern / include -I / usr / local / MATLAB / R2013b / simulink / include -DMATLAB_MEX_FILE -ansi - D_GNU_SOURCE -I / usr / local / MATLAB / R2013b / extern / include / cpp -I / usr / local / MATLAB / R2013b / extern / include -DGLNXA64 -DGCC -DMX_COMPAT_32 -DNDEBUG -Wno-effc ++)
find_package(Boost COMPONENTS program_options系统文件系统regex必需)
find_package(PkgConfig必需)
pkg_check_modules(GTKMM gtkmm-3.0)
include_directories($ {GTKMM_INCLUDE_DIRS})
include_directories($ {Boost_INCLUDE_DIR})
include_directories($ {PROJECT_SOURCE_DIR})
## link_directories(/ usr / local / MATLAB / R2013b / bin / glnxa64)
## target_link_libraries($ {TARGET} eng)
## target_link_libraries($ {TARGET} mx)
set(CMAKE_CXX_FLAGS--std = c ++ 11)
add_executable($ {TARGET } $ {MAIN_SOURCES})
target_link_libraries($ {TARGET} $ {GTKMM_LIBRARIE ($ {TARGET})
target_link_libraries $ b #target_link_libraries($ {TARGET} LINK_PRIVATE /usr/local/MATLAB/R2013b/bin/glnxa64/libmx.so)#mx
target_link_libraries($ {TARGET} andor)
$ c $您可以尝试使用 Wiki / CMake / Tutorials / Exporting_and_Importing_Targets#Importing_Targetsrel =nofollow> import target :共享导入)
set_property(TARGET ENG PROPERTY IMPORTED_LOCATION /usr/local/MATLAB/R2013b/bin/glnxa64/libeng.so)
...
add_executable($ {TARGET} $ {MAIN_SOURCES })
...
target_link_libraries($ {TARGET} eng)
对于调试,您可以尝试使用 make VERBOSE = 1 进行构建。
这将向您显示使用的gcc命令l国家统计局。
CMake可能会将 target_link_libraries 命令转换为以下内容:
g ++ ... - L / usr / local / MATLAB / R2013b / bin / glnxa64 -leng ...
gcc then find在这个文件夹中增加一些库。
I have a cmake project where I want to add a class containing the matlab engine. For compiling it I need to include two libraries eng
and mx
, which I do by adding
target_link_libraries( ${TARGET} /usr/local/MATLAB/R2013b/bin/glnxa64/libeng.so)
target_link_libraries( ${TARGET} /usr/local/MATLAB/R2013b/bin/glnxa64/libmx.so)
to my CMakeLists.txt
file.
However there are also lots of other old versions of libraries in /usr/local/MATLAB/R2013b/bin/glnxa64/
, which seem
to be automatically added to the path as well when calling the above command. I think this causes the compiler to not find my
normal libraries anymore and produces an error.
How can I include only the two above libraries, and not all the others in the glnxa64
folder?
The warning shown after running cmake .
:
CMake Warning at CMakeLists.txt:23 (add_executable):
Cannot generate a safe runtime search path for target CCDWidget because
files in some directories may conflict with libraries in implicit
directories:
runtime library [libboost_program_options.so.1.49.0] in /usr/lib may be hidden by files in:
/usr/local/MATLAB/R2013b/bin/glnxa64
runtime library [libboost_system.so.1.49.0] in /usr/lib may be hidden by files in:
/usr/local/MATLAB/R2013b/bin/glnxa64
runtime library [libboost_filesystem.so.1.49.0] in /usr/lib may be hidden by files in:
/usr/local/MATLAB/R2013b/bin/glnxa64
runtime library [libboost_regex.so.1.49.0] in /usr/lib may be hidden by files in:
/usr/local/MATLAB/R2013b/bin/glnxa64
Some of these libraries may not be found correctly.
And the error message during linking:
Linking CXX executable CCDWidget
/usr/lib/x86_64-linux-gnu/libharfbuzz.so.0: undefined reference to `FT_Face_GetCharVariantIndex'
/usr/lib/x86_64-linux-gnu/libharfbuzz.so.0: undefined reference to `FT_Get_Advance'
collect2: error: ld returned 1 exit status
make[2]: *** [CCDWidget] Error 1
make[1]: *** [CMakeFiles/CCDWidget.dir/all] Error 2
make: *** [all] Error 2
Below is my full CMakeLists.txt
file. Lines commented out with two ## are alternatives that I tried before and didn't solve my problem.
I also added LINK_PRIVATE
to the target_link_libraries command as shown in the code below, which didn't make a difference.
The option PRIVATE
alone seems to be not accepted by my cmake version, as it changed the error meassage to
/usr/bin/ld: cannot find -lPRIVATE
collect2: error: ld returned 1 exit status
When the #eng
line is commented out, the compilation and linking works without errors
(when calling the matlab engine is also commented out in Readout.cpp
), so the error must be produced by that line.
#Specify the version being used as well as the language
cmake_minimum_required(VERSION 2.6)
##cmake_policy(SET CMP0003 NEW)
#Name your project here
project(CCDWidget)
set(TARGET CCDWidget)
set(MAIN_SOURCES CCDWidget.cpp main.cc CCDControl.cpp VideoWindow.cpp ImageWindow.cpp ThisMeasurement.cpp KineticSeries.cpp FastKinetics.cpp Readout.cpp)
##SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
#set_source_files_properties(Readout.cpp PROPERTIES COMPILE_FLAGS "-I/usr/local/MATLAB/R2013b/extern/include -I/usr/local/MATLAB/R2013b/simulink/include -DMATLAB_MEX_FILE -ansi -D_GNU_SOURCE -I/usr/local/MATLAB/R2013b/extern/include/cpp -I/usr/local/MATLAB/R2013b/extern/include -DGLNXA64 -DGCC -DMX_COMPAT_32 -DNDEBUG -Wno-effc++")
find_package(Boost COMPONENTS program_options system filesystem regex REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(GTKMM gtkmm-3.0)
include_directories( ${GTKMM_INCLUDE_DIRS} )
include_directories( ${Boost_INCLUDE_DIR} )
include_directories( ${PROJECT_SOURCE_DIR} )
##link_directories(/usr/local/MATLAB/R2013b/bin/glnxa64)
##target_link_libraries( ${TARGET} eng)
##target_link_libraries( ${TARGET} mx)
set(CMAKE_CXX_FLAGS "--std=c++11")
add_executable( ${TARGET} ${MAIN_SOURCES} )
target_link_libraries( ${TARGET} ${GTKMM_LIBRARIES} )
target_link_libraries( ${TARGET} ${Boost_LIBRARIES} )
target_link_libraries( ${TARGET} LINK_PRIVATE /usr/local/MATLAB/R2013b/bin/glnxa64/libeng.so) # eng
#target_link_libraries( ${TARGET} LINK_PRIVATE /usr/local/MATLAB/R2013b/bin/glnxa64/libmx.so ) # mx
target_link_libraries( ${TARGET} andor )
You could try using an imported target:
add_library(eng SHARED IMPORTED)
set_property(TARGET eng PROPERTY IMPORTED_LOCATION /usr/local/MATLAB/R2013b/bin/glnxa64/libeng.so)
...
add_executable( ${TARGET} ${MAIN_SOURCES} )
...
target_link_libraries(${TARGET} eng)
For debugging you could try to build with "make VERBOSE=1".
This will show you the used gcc command line.
CMake probably transforms your target_link_libraries command to something like:
g++ ... -L/usr/local/MATLAB/R2013b/bin/glnxa64 -leng ...
gcc then finds some boost libraries in this folder.
这篇关于链接路径混淆target_link_libraries调用后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!