私は 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