如何使用 CMake 强制 c++ 编译器使用不同已安装包的版本之一?
How to force c++ compiler use one of different installed package's versions, using CMake?
ROS Fuerte 我安装在我的机器上使用opencv 2.2。我想使用刚刚安装的 2.4.9 版本。它的位置是/home/polar/soft/lib/opencv/opencv-2.4.9/build/lib
。
请问如何使用CMake?从我的搜索来看,似乎find_library
可以解决问题,但无法使其工作。
== 我在我的 cpp 代码中包含 opencv 像这样
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/opencv.hpp>
#include "opencv2/imgproc/imgproc.hpp"
============ 在这里我的 CMAKE
cmake_minimum_required(VERSION 2.8)
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)
rosbuild_init()
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
rosbuild_genmsg()
rosbuild_gensrv()
# GSL
find_package( PkgConfig REQUIRED)
pkg_check_modules( gsl REQUIRED gsl )
SET(corners_opencv_flag ok)
#*******************************************************************
#*******************************************************************
#****** CORNERS OPENCV
#*******************************************************************
#*******************************************************************
if(corners_opencv_flag)
#---
SET(execFiles_corner_opencv
corner_v1
)
#---
foreach(file_ros ${execFiles_corner_opencv})
rosbuild_add_executable(${file_ros} computer-vision/corners/${file_ros}.cpp )
endforeach(file_ros)
#---
endif(corners_opencv_flag)
#-------------------
# STACK
#--------------------
SET(FILES_TO_RUN
${execFiles_corner_opencv}
)
#=======================================================
#
# CUSTOM LIBRARIES
#
#
#=======================================================
PROJECT(VOLCANO)
SET(SRC ${VOLCANO_SOURCE_DIR}/src)
#******* boost
find_package( Boost REQUIRED COMPONENTS program_options regex )
include_directories( ${Boost_INCLUDE_DIRS} )
if(Boost_FOUND)
message("nn Boost found nn")
endif()
find_package(OpenCV REQUIRED PATHS /home/polar/soft/lib/opencv/opencv-2.4.9/cmake)
#===== Calculus
include_directories(${SRC}/calculus)
include_directories(${SRC}/calculus/matrix)
SET(MY_LIB
${MY_LIB}
Calculus
CholeskyDecompose
)
#-------------------------------------------
# Linking the executables against the
#-------------------------------------------
foreach(file2link ${FILES_TO_RUN})
target_link_libraries(${file2link}
${MY_LIB}
${MY_LIB}
${gsl_LIBRARIES}
${Boost_PROGRAM_OPTIONS_LIBRARY} ${Boost_REGEX_LIBRARY}
${OpenCV_LIB}
)
endforeach(file2link)
#--- sources folders
ADD_SUBDIRECTORY(src)
将其添加到您的 CMakeList 中.txt替换前面的find_package(OpenCV)
行:
find_package(OpenCV REQUIRED PATHS /home/polar/soft/lib/opencv/opencv-2.4.9/cmake)
在你的opencv安装中应该有一个cmake目录。
所以,正如我所怀疑的那样,target_link_libraries(${file2link} .... ${OpenCV_LIB})
问题是:OpenCV_LIB
似乎分配了。
现在,我以这种方式链接opencv,它可以工作:
find_package(OpenCVV 2.4.9 PATHS /home/polar/soft/lib/opencv/opencv-2.4.9/cmake)
...
target_link_libraries(${file2link} .... ${OpenCVV_LIB})
事实上,我只是用了另一个名字,但OpenCV
.
@texasflood,感谢您的帮助。
这里有很多混乱,没有适当的代码来巩固建议。
cmake_minimum_required(VERSION 3.1)
project( DisplayImage )
# Enable C++11
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
# For OpenCV 4
SET(OpenCV_DIR <current-path>/Learning/opencv-installation/installation/OpenCV-master/lib/cmake/opencv4)
# For OpenCV 3
# SET(OpenCV_DIR "<current-path>/opencv3.4.8/installation/OpenCV-3.4.8/share/OpenCV/")
# If the package has been found, several variables will
# be set, you can find the full list with descriptions
# in the OpenCVConfig.cmake file.
# Print some message showing some of them
message(STATUS "OpenCV library status:")
message(STATUS " version: ${OpenCV_VERSION}")
message(STATUS " libraries: ${OpenCV_LIBS}")
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
add_executable( DisplayImage main.cpp )
target_link_libraries( DisplayImage ${OpenCV_LIBS} )
谢谢。
相关文章:
- OpenGL 在 VMWare Fusion 版本 10.1.3 上安装的虚拟机 (Ubuntu 16.04) 上崩溃
- Visual studio安装项目删除以前的版本
- 在CentOS 7上安装GCC 7.4.0不会更新我的LIBSTDC 版本
- 该程序是针对协议缓冲区运行时库的2.6.1版本编译的,该版本与已安装的版本(3.5.0)不兼容
- 在 CentOS 7 上通过 devtoolset-4 安装的 Eclipse CDT 使用了错误版本的 gcc/g++
- 我如何在VS 2017中的Windows安装程序安装Windows安装程序应配置What what版本
- 在Mac上安装使用Homebrew的特定版本的Boost
- 安装 2 个或更多次要版本的 Visual Studio
- 我已安装的GCC版本是我已安装的RedHat开发人员工具集的背后
- 安装 Python3.6 版本的 Boost-Python3
- 即使我安装了正确的libprotoc版本,也会看到libprotobuf致命错误
- 使用git安装多个版本的软件
- 在安装了两个不同 Boost 版本的系统上编译C++代码
- 安装多个版本的G (或GCC)
- Qt安装程序框架 - 读取下载的软件包版本
- 当我安装了多个Visual Studio版本时,如何使用Visual Studio 2008构建boost
- gcc版本显示4.2.1,即使在安装了4.9(Homebrew)之后也是如此
- 无法安装已安装64位版本Anaconda的提升库
- 在C++托管中,调试和安装版本之间的XOR行为不一致
- OSX 10.10.5 - c++库,如何更改链接或添加环境标志,以酿造安装版本