我的包CMakeLists.txt
,我从另一个库(NewLib)的另一个包编译了libNewLib.so
。我还包括我所包含的那个库的头文件:
set(LIB_MANUALLY "${CMAKE_CURRENT_SOURCE_DIR}/lib/") #I put the file libNewLib.so here
include_directories(
include/NewLib
)
LINK_DIRECTORIES(${LIB_MANUALLY})
target_link_libraries(estimation libNewLib.so)
但我仍然得到错误:
/usr/bin/ld: cannot find -lNewLib
这是正确的方法吗? 我尝试了几种解决方案,但它没有用。
我正在使用Ros kinetic
catkin
包
make VERSION 2.8.3
完整CMakeLists.txt
:
cmake_minimum_required(VERSION 2.8.3)
project(localization)
add_compile_options(-std=c++11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Ofast -march=native")
set(LIB_MANUALLY "${CMAKE_CURRENT_SOURCE_DIR}/lib/")
message(STATUS "LIB_MANUALLY : ${LIB_MANUALLY}")
find_package(catkin REQUIRED COMPONENTS
cv_bridge
image_transport
roscpp
rospy
std_msgs
)
find_package(OpenCV REQUIRED
NO_MODULE # should be optional, tells CMake to use config mode
PATHS /usr/local # look here
NO_DEFAULT_PATH) # and don't look anywhere else
catkin_package(
# INCLUDE_DIRS include
# LIBRARIES localization
CATKIN_DEPENDS cv_bridge image_transport roscpp rospy std_msgs
# DEPENDS system_lib
)
include_directories(
include
include/NewLib
${catkin_INCLUDE_DIRS}
${OpenCV_INCLUDE_DIRS}
)
add_executable(estimation
src/pose_map_estimation.cpp
src/pose_map_estimation_main.cpp
)
target_link_libraries(estimation ${catkin_LIBRARIES} ${OpenCV_LIBRARIES} libNewLib.so)
LINK_DIRECTORIES(${LIB_MANUALLY})
答案 0 :(得分:0)
在https://cmake.org/cmake/help/v3.0/command/link_directories.html中说:
指定链接器应搜索库的路径。该命令仅适用于调用后创建的目标。
因此,如果在link_directories命令之后创建目标,请尝试它是否有效。
您还可以考虑编写一个正确的cmake文件来查找您的库,并使用find_package来查找它。