How to change directory of a library in a package

2019-07-18 08:37发布

I have installed opencv2.4.9(With No CUDA) by unzip opencv2.4.9.zip in home. Many successful codes are using this library. Now I wanna rebuild opencv2.4.9(with CUDA) in another folder. I don't wanna delete the previous folder because I don't wanna face any problem later on and make my older code can't function.

So, the question is how to change the name of the directory? Seems like we link the package with library in CMake like below:

include_directories( ${catkin_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS} )

find_package( OpenCV REQUIRED )

find_package(catkin REQUIRED COMPONENTS cv_bridge image_transport OpenCV roscpp rospy std_msgs )

the name of directory is just OpenCV. So if I got more than one OpenCV library in home, how could I link them separately?

And how to make c++ link to the library if we could change the name?

add_executable(xxx src/xxx.cpp)

target_link_libraries(xxx ${catkin_LIBRARIES} ${OpenCV_LIBRARIES})

1条回答
【Aperson】
2楼-- · 2019-07-18 09:19

Libraries can be included and linked with include_directories() and link_directories(), like this:

cmake_minimum_required(VERSION 2.4.6)
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)
...
include_directories(${PROJECT_SOURCE_DIR})

include_directories(/path/to/opencv/OpenCV-2.4.1/include)
link_directories(/path/to/opencv/OpenCV-2.4.1/lib)
...

# Set the build type.  Options are:
#  Coverage       : w/ debug symbols, w/o op ...

So you should not forget the linking in the CMakeLists.txt and maybe remove the standard linking to your current OpenCV libs.

查看更多
登录 后发表回答