Issue
I have a program that depends on
#include <fstream>
#include <vector>
#include <opencv2/opencv.hpp>
Its CMakeLists
is the following
cmake_minimum_required(VERSION 3.5)
project(CirclesDetectionProject VERSION 0.1)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
# OpenCV
find_package(OpenCV REQUIRED PATHS "C:/opencv/build/x64/mingw64/")
include_directories(${OpenCV_INCLUDE_DIRS})
set(PROJECT_SOURCES
main.cpp
)
add_executable(CirclesDetection ${PROJECT_SOURCES})
target_link_libraries(CirclesDetection ${OpenCV_LIBS})
I'm using VScode on windows 10 and the code compiling and running correctly using mingw32-make
.
My question is how can I generate an executable that can run on other windows machines that don't necessarily have the dependencies installed?
Solution
I used CFE explorer
which tells you all ddls that the exe need, which is very useful. in my case, it showed me that I have those dependencies:
libwinpthread-1.dll
libopencv_core480.dll
libopencv_imgcodecs480.dll
liboopencv_imgproc480.dll
kernel32.dll
msvcrt.dll
For libwinpthread-1.dll
I had to add this to my CMakeLists
to ensure static linking:
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static -static-libgcc -static-libstdc++")
Then for OpenCV
, I did recompile it from source in static mode and recompile my code using the static version of OpenCV. Make sure it is using the static one:
set(OpenCV_DIR "C:/opencv-4.7.0-static/build/x64/mingw64/")
find_package(OpenCV REQUIRED)
Finally, for kernel32.dll
and msvcrt.dll
, they are standard windows system libraries and they are present on every Windows machine, so you don't have to worry about them.
Answered By - Ja_cpp Answer Checked By - Marie Seifert (WPSolving Admin)