1

I am building a c++ project with CMake, this project depends on OpenCV library that was installed using Vcpkg.

Here is my CMakeList.txt file :

# 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 file :

#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;
}

I am using these commands to build these project :

  1. cmake ..\CMakeProject2 -G "MinGW Makefiles" -DCMAKE_TOOLCHAIN_FILE=C:\vcpkg\scripts\buildsystems\vcpkg.cmake
  2. make

and this is what i get :

\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
mloskot
  • 37,086
  • 11
  • 109
  • 136

2 Answers2

0

I had to run those commands :

cmake -G "Visual Studio 15 2017 Win64" -DCMAKE_TOOLCHAIN_FILE=C:\vcpkg\scripts\buildsystems\vcpkg.cmake ..

and

cmake --build . --config Release
0

Shortly, you can not use -G "MinGW Makefiles".

Currently, vcpkg does not offer support for MinGW.

It was requested, but eventually it has not been implemented and the concluding comment from the vcpkg maintainers consists of this suggestion for anyone who would like to pick the MinGW support again:

However, we have not looked much into using mingw so far. If you have a functioning CMake toolchain file, you can follow our triplet documentation[1] to create a triplets/x64-windows-mingw.cmake file that will use that toolchain to build libraries.

[1] https://github.com/Microsoft/vcpkg/blob/master/docs/users/triplets.md

mloskot
  • 37,086
  • 11
  • 109
  • 136