I try to set up a C++ environment for working with images (using opencv) and parallel computing. The main problem is that I can't success to link all the pieces together. As a mention, I use mingw from console (windows cmd), not from an IDE
What I did by now:
- I added mingw bin to the system Path variable; if I run gcc cplusplus.cpp -o ccc -fopenmp -lstdc++ on cmd, it works fine (with #include <omp.h> in the cplusplus.cpp file)
now for CMake and opencv:
- I added CMake bin to system Path variable
- I added \opencv\build\x64\vc16\lib and \opencv\build\x64\vc16\bin to the system Path variable
NOW, the problem appear when I try to build mingw with CMake I think. This is c++ file:
#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>
#include <omp.h>
using namespace std;
int main() {
#pragma omp parallel
{
int d = omp_get_thread_num();
cout<<d<<" Hello world"<<endl;
}
return 0;
}
This is CMakeLists.txt:
cmake_minimum_required(VERSION 3.0)
project(OpenCV_cpp)
find_package(OpenCV REQUIRED)
find_package(OpenMP)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
include_directories(${OpenCV_INCLUDE-DIRECTORIES})
add_executable(display_image cplusplus.cpp)
target_link_libraries(display_image ${OpenCV_LIBS})
In cmd: cmake . -G "MinGW Makefiles" works fine (ends without errors). But if I run mingw32-make.exe I get errors:
[ 50%] Linking CXX executable display_image.exe
d:/winlibs-x86_64-posix-seh-gcc-12.2.0-llvm-15.0.7-mingw-w64ucrt-10.0.0-r4/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\display_image.dir/objects.a(cplusplus.cpp.obj):cplusplus.cpp:(.text+0xe): undefined reference to 'omp_get_thread_num'
collect2.exe: error: ld returned 1 exit status
mingw32-make[2]: *** [CMakeFiles\display_image.dir\build.make:115: display_image.exe] Error 1
mingw32-make[1]: *** [CMakeFiles\Makefile2:82: CMakeFiles/display_image.dir/all] Error 2
mingw32-make: *** [makefile:90: all] Error 2
As you can see from the error, the issue is related to openMP. How can I solve this?
EDIT: the above errors were solved, but now appeared a 'entry point could not be located' error - see the comments for details.