我正在使用CMake构建一个c ++项目,该项目取决于使用Vcpkg安装的OpenCV库。
这是我的CMakeList.txt
文件:
# CMakeList.txt : CMake project for CMakeProject2, include source and define
# project specific logic here.
#
cmake_minimum_required (VERSION 3.8)
set( CMAKE_TOOLCHAIN_FILE "C:/vcpkg/scripts/buildsystems/vcpkg.cmake" )
# Find Package
find_package( OpenCV REQUIRED )
# Additional Include Directories
include_directories( ${OpenCV_INCLUDE_DIRS} )
message("hello world " ${OpenCV_LIB_DIR} ${OpenCV_LIBS})
# Additional Library Directories
link_directories( ${OpenCV_LIB_DIR} )
link_libraries(${OpenCV_LIBS})
#set( OpenCV_DIR "C:/vcpkg/installed/x64-windows/share/opencv" )
# Add source to this project's executable.
add_executable (CMakeProject2 "CMakeProject2.cpp" "CMakeProject2.h")
# Additional Dependencies
target_link_libraries( CMakeProject2 ${OpenCV_LIBS} )
CMakeProject2.cpp文件:
#include "CMakeProject2.h"
#include <iostream>
#include "opencv2/opencv.hpp"
using namespace cv;
using namespace std;
int main()
{
cout << "OpenCV version : " << CV_VERSION << endl;
cout << "Hello CMake." << endl;
return 0;
}
我正在使用这些命令来构建这些项目:
cmake ..\CMakeProject2 -G "MinGW Makefiles" -DCMAKE_TOOLCHAIN_FILE=C:\vcpkg\scripts\buildsystems\vcpkg.cmake
make
这就是我得到的:
\CMakeProject2\build>make
[ 50%] Linking CXX executable CMakeProject2.exe
CMakeFiles\CMakeProject2.dir/objects.a(CMakeProject2.cpp.obj):CMakeProject2.cpp:(.text$_ZN2cv6StringD1Ev[_ZN2cv6StringD1Ev]+0x11): undefined reference to `cv::String::deallocate()'
CMakeFiles\CMakeProject2.dir/objects.a(CMakeProject2.cpp.obj):CMakeProject2.cpp:(.text$_ZN2cv6StringaSERKS0_[_ZN2cv6StringaSERKS0_]+0x25): undefined reference to `cv::String::deallocate()'
collect2.exe: error: ld returned 1 exit status
make[2]: *** [CMakeProject2.exe] Erreur 1
make[1]: *** [CMakeFiles/CMakeProject2.dir/all] Erreur 2
make: *** [all] Erreur 2
答案 0 :(得分:0)
我必须运行那些命令:
cmake -G "Visual Studio 15 2017 Win64" -DCMAKE_TOOLCHAIN_FILE=C:\vcpkg\scripts\buildsystems\vcpkg.cmake ..
和
cmake --build . --config Release
答案 1 :(得分:0)
很快,您将无法使用-G "MinGW Makefiles"
。
当前,vcpkg不提供对MinGW的支持。
它是requested,但最终它是not been implemented,vcpkg维护者的总结意见包括对任何希望再次获得MinGW支持的人的建议:
但是,到目前为止,我们尚未对使用mingw进行过多研究。如果你有 一个有效的CMake工具链文件,您可以按照我们的三元组 documentation [1]创建一个
triplets/x64-windows-mingw.cmake
文件 将使用该工具链来构建库。[1] https://github.com/Microsoft/vcpkg/blob/master/docs/users/triplets.md