I have a C++ program that uses protobuf and asio, which compiles fine under Linux using g++. I am wondering how I could go about making a new preset which allows me to compile this program into a windows executable.
I have tried using mingw compiler, but it seems I do not understand how to use it properly.
This is my CmakePresets.json
{
"version": 8,
"configurePresets": [
{
"name": "debug",
"displayName": "Debug",
"description": "Using compiler: CXX = /usr/bin/g++",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"cacheVariables": {
"CMAKE_CXX_COMPILER": "/usr/bin/g++",
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "windows-debug",
"displayName": "Windows Debug",
"description": "Using compiler: CXX = /usr/bin/x86_64-w64-mingw32-g++",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"cacheVariables": {
"CMAKE_SYSTEM_NAME": "Windows",
"CMAKE_CXX_COMPILER": "/usr/bin/x86_64-w64-mingw32-g++",
"CMAKE_BUILD_TYPE": "Debug"
}
}
],
"buildPresets": [
{
"name": "debug",
"configurePreset": "debug"
},
{
"name": "windows-debug",
"configurePreset": "windows-debug"
}
]
}
CMake generation fails because it can’t find “ZLIB::ZLIB”:
[main] Configuring project: dark-proxy
[proc] Executing command: /usr/bin/cmake -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_CXX_COMPILER=/usr/bin/x86_64-w64-mingw32-g++ -DCMAKE_BUILD_TYPE=Debug -S/home/burger/Desktop/dark-proxy -B/home/burger/Desktop/dark-proxy/out/build/windows-debug
[cmake] -- Could NOT find ZLIB (missing: ZLIB_LIBRARY) (found version "1.3")
[cmake] CMake Warning at /usr/local/lib/cmake/protobuf/protobuf-config.cmake:9 (find_package):
[cmake] Found package configuration file:
[cmake]
[cmake] /usr/local/lib/cmake/absl/abslConfig.cmake
[cmake]
[cmake] but it set absl_FOUND to FALSE so package "absl" is considered to be NOT
[cmake] FOUND. Reason given by package:
[cmake]
[cmake] The following imported targets are referenced, but are missing:
[cmake] protobuf::gmock
[cmake]
[cmake] Call Stack (most recent call first):
[cmake] protos/CMakeLists.txt:1 (find_package)
[cmake]
[cmake]
[cmake] -- Found Protobuf package with version : 29.0.0
[cmake] -- Configuring done (0.0s)
[cmake] CMake Error at /usr/local/lib/cmake/protobuf/protobuf-targets.cmake:70 (set_target_properties):
[cmake] The link interface of target "protobuf::libprotobuf" contains:
[cmake]
[cmake] ZLIB::ZLIB
[cmake]
[cmake] but the target was not found. Possible reasons include:
[cmake]
[cmake] * There is a typo in the target name.
[cmake] * A find_package call is missing for an IMPORTED target.
[cmake] * An ALIAS target is missing.
[cmake]
[cmake] Call Stack (most recent call first):
[cmake] /usr/local/lib/cmake/protobuf/protobuf-config.cmake:16 (include)
[cmake] protos/CMakeLists.txt:1 (find_package)
[cmake]
[cmake]
[cmake] -- Generating done (0.0s)
[cmake] CMake Generate step failed. Build files cannot be regenerated correctly.
[proc] The command: /usr/bin/cmake -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_CXX_COMPILER=/usr/bin/x86_64-w64-mingw32-g++ -DCMAKE_BUILD_TYPE=Debug -S/home/burger/Desktop/dark-proxy -B/home/burger/Desktop/dark-proxy/out/build/windows-debug exited with code: 1
This is what the Cmake generation looks like when I use g++:
[main] Configuring project: dark-proxy
[proc] Executing command: /usr/bin/cmake -DCMAKE_CXX_COMPILER=/usr/bin/g++ -DCMAKE_BUILD_TYPE=Debug -S/home/burger/Desktop/dark-proxy -B/home/burger/Desktop/dark-proxy/out/build/debug
[cmake] CMake Warning at /usr/local/lib/cmake/protobuf/protobuf-config.cmake:9 (find_package):
[cmake] Found package configuration file:
[cmake]
[cmake] /usr/local/lib/cmake/absl/abslConfig.cmake
[cmake]
[cmake] but it set absl_FOUND to FALSE so package "absl" is considered to be NOT
[cmake] FOUND. Reason given by package:
[cmake]
[cmake] The following imported targets are referenced, but are missing:
[cmake] protobuf::gmock
[cmake]
[cmake] Call Stack (most recent call first):
[cmake] protos/CMakeLists.txt:1 (find_package)
[cmake]
[cmake]
[cmake] -- Found Protobuf package with version : 29.0.0
[cmake] -- Configuring done (0.0s)
[cmake] -- Generating done (0.0s)
[cmake] -- Build files have been written to: /home/burger/Desktop/dark-proxy/out/build/debug
How do I use mingw to compile my project in the same way that g++ works to get a windows executable?
1