I have a cmake-based C++ project using boost and zmq libraries.
I'm trying to build it on Windows using Visual Studio Community 2017 and vcpkg.
I installed vcpkg following the instructions on the project page.
Now I can see the required packages installed:
PS C:\Users\me\source\repos\vcpkg> .\vcpkg list
boost-accumulators:x64-windows 1.67.0 Boost accumulators module
boost-accumulators:x86-windows 1.67.0 Boost accumulators module
boost-algorithm:x64-windows 1.67.0 Boost algorithm module
boost-algorithm:x86-windows 1.67.0 Boost algorithm module
…
boost-variant:x64-windows 1.67.0 Boost variant module
boost-variant:x86-windows 1.67.0 Boost variant module
boost-vcpkg-helpers:x64-windows 4 a set of vcpkg-internal scripts used to modulari...
boost-vcpkg-helpers:x86-windows 4 a set of vcpkg-internal scripts used to modulari...
boost-vmd:x64-windows 1.67.0 Boost vmd module
boost-vmd:x86-windows 1.67.0 Boost vmd module
boost-wave:x64-windows 1.67.0 Boost wave module
boost-wave:x86-windows 1.67.0 Boost wave module
boost-winapi:x64-windows 1.67.0 Boost winapi module
boost-winapi:x86-windows 1.67.0 Boost winapi module
boost-xpressive:x64-windows 1.67.0 Boost xpressive module
boost-xpressive:x86-windows 1.67.0 Boost xpressive module
boost:x64-windows 1.67.0 Peer-reviewed portable C++ source libraries
boost:x86-windows 1.67.0 Peer-reviewed portable C++ source libraries
bzip2:x64-windows 1.0.6-2 High-quality data compressor.
bzip2:x86-windows 1.0.6-2 High-quality data compressor.
liblzma:x64-windows 5.2.3-2 Compression library with an API similar to that ...
liblzma:x86-windows 5.2.3-2 Compression library with an API similar to that ...
openssl:x64-windows 1.0.2o-3 OpenSSL is an open source project that provides ...
openssl:x86-windows 1.0.2o-3 OpenSSL is an open source project that provides ...
protobuf:x64-windows 3.5.1-5 Protocol Buffers - Google's data interchange format
protobuf:x86-windows 3.5.1-5 Protocol Buffers - Google's data interchange format
python3:x64-windows 3.6.4-2 The Python programming language as an embeddable...
python3:x86-windows 3.6.4-2 The Python programming language as an embeddable...
zeromq:x64-windows 2018-07-01 The ZeroMQ lightweight messaging kernel is a lib...
zeromq:x86-windows 2018-07-01 The ZeroMQ lightweight messaging kernel is a lib...
zlib:x64-windows 1.2.11-3 A compression library
zlib:x86-windows 1.2.11-3 A compression library
I also ran .\vcpkg integrate install to enable integration:
PS C:\Users\me\source\repos\vcpkg> .\vcpkg integrate install
Applied user-wide integration for this vcpkg root.
All MSBuild C++ projects can now #include any installed libraries.
Linking will be handled automatically.
Installing new libraries will make them instantly available.
CMake projects should use: "-DCMAKE_TOOLCHAIN_FILE=C:/Users/me/source/repos/vcpkg/scripts/buildsystems/vcpkg.cmake"
Next, Visual Studio is able to open the CMake project right away. The only thing I need to add apparently is the toolchain file. So I go to CMakeLists.txt -> "Change CMake settings", and set "cmakeCommandArgs": "-DCMAKE_TOOLCHAIN_FILE=C:/Users/me/source/repos/vcpkg/scripts/buildsystems/vcpkg.cmake" for every target (there are 4 targets, debug/release x x86/x64).
But as soon as CMake is restarted, as I see in the Visual Studio's "Output" pane, still it can't find the dependencies:
1> Command line: C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2017\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe -G "Ninja" -DCMAKE_INSTALL_PREFIX:PATH="C:\Users\me\CMakeBuilds\55e700de-d370-f634-bc40-455cedaf329e\install\x86-Debug" -DCMAKE_CXX_COMPILER="C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.14.26428/bin/HostX86/x86/cl.exe" -DCMAKE_C_COMPILER="C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.14.26428/bin/HostX86/x86/cl.exe" -DCMAKE_TOOLCHAIN_FILE=C:/Users/me/source/repos/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_BUILD_TYPE="Debug" -DCMAKE_MAKE_PROGRAM="C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2017\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" "C:\Users\me\Source\Repos\bluezero"
1> Working directory: C:\Users\me\CMakeBuilds\55e700de-d370-f634-bc40-455cedaf329e\build\x86-Debug
1> -- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)
1> CMake Warning at C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake:587 (message):
1> Imported targets and dependency information not available for Boost version
1> (all versions older than 1.33)
1> Call Stack (most recent call first):
1> C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake(950): (_Boost_COMPONENT_DEPENDENCIES)
1> C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake(1618): (_Boost_MISSING_DEPENDENCIES)
1> C:\Users\me\Source\Repos\bluezero\CMakeLists.txt(44): (find_package)
1>
1>
1> CMake Warning at C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake:587 (message):
1> Imported targets and dependency information not available for Boost version
1> (all versions older than 1.33)
1> Call Stack (most recent call first):
1> C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake(950): (_Boost_COMPONENT_DEPENDENCIES)
1> C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake(1618): (_Boost_MISSING_DEPENDENCIES)
1> C:\Users\me\Source\Repos\bluezero\CMakeLists.txt(44): (find_package)
1>
1>
1> CMake Warning at C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake:587 (message):
1> Imported targets and dependency information not available for Boost version
1> (all versions older than 1.33)
1> Call Stack (most recent call first):
1> C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake(950): (_Boost_COMPONENT_DEPENDENCIES)
1> C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake(1618): (_Boost_MISSING_DEPENDENCIES)
1> C:\Users\me\Source\Repos\bluezero\CMakeLists.txt(44): (find_package)
1>
1>
1> CMake Warning at C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake:587 (message):
1> Imported targets and dependency information not available for Boost version
1> (all versions older than 1.33)
1> Call Stack (most recent call first):
1> C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake(950): (_Boost_COMPONENT_DEPENDENCIES)
1> C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake(1618): (_Boost_MISSING_DEPENDENCIES)
1> C:\Users\me\Source\Repos\bluezero\CMakeLists.txt(44): (find_package)
1>
1>
1> CMake Warning at C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake:587 (message):
1> Imported targets and dependency information not available for Boost version
1> (all versions older than 1.33)
1> Call Stack (most recent call first):
1> C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake(950): (_Boost_COMPONENT_DEPENDENCIES)
1> C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake(1618): (_Boost_MISSING_DEPENDENCIES)
1> C:\Users\me\Source\Repos\bluezero\CMakeLists.txt(44): (find_package)
1>
1>
1> CMake Warning at C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake:587 (message):
1> Imported targets and dependency information not available for Boost version
1> (all versions older than 1.33)
1> Call Stack (most recent call first):
1> C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake(950): (_Boost_COMPONENT_DEPENDENCIES)
1> C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake(1618): (_Boost_MISSING_DEPENDENCIES)
1> C:\Users\me\Source\Repos\bluezero\CMakeLists.txt(44): (find_package)
1>
1>
1> CMake Error at C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake:2044 (message):
1> Unable to find the requested Boost libraries.
1>
1> Unable to find the Boost header files. Please set BOOST_ROOT to the root
1> directory containing Boost or BOOST_INCLUDEDIR to the directory containing
1> Boost's headers.
1> Call Stack (most recent call first):
1> C:\Users\me\Source\Repos\bluezero\CMakeLists.txt(44): (find_package)
1>
1>
1> CMake Error at C:\Users\me\Source\Repos\bluezero\CMakeLists.txt:46 (find_package):
1> Could not find a package configuration file provided by "ZeroMQ" with any
1> of the following names:
1>
1> ZeroMQConfig.cmake
1> zeromq-config.cmake
1>
1> Add the installation prefix of "ZeroMQ" to CMAKE_PREFIX_PATH or set
1> "ZeroMQ_DIR" to a directory containing one of the above files. If "ZeroMQ"
1> provides a separate development package or SDK, be sure it has been
1> installed.
1>
1>
1> -- Configuring incomplete, errors occurred!
1> See also "C:/Users/me/CMakeBuilds/55e700de-d370-f634-bc40-455cedaf329e/build/x86-Debug/CMakeFiles/CMakeOutput.log".
1> See also "C:/Users/me/CMakeBuilds/55e700de-d370-f634-bc40-455cedaf329e/build/x86-Debug/CMakeFiles/CMakeError.log".
1> C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2017\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe -G "Ninja" -DCMAKE_INSTALL_PREFIX:PATH="C:\Users\me\CMakeBuilds\55e700de-d370-f634-bc40-455cedaf329e\install\x86-Debug" -DCMAKE_CXX_COMPILER="C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.14.26428/bin/HostX86/x86/cl.exe" -DCMAKE_C_COMPILER="C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.14.26428/bin/HostX86/x86/cl.exe" -DCMAKE_TOOLCHAIN_FILE=C:/Users/me/source/repos/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_BUILD_TYPE="Debug" -DCMAKE_MAKE_PROGRAM="C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2017\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" "C:\Users\me\Source\Repos\bluezero" returned with exit code: 1
CMake Warning at C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake:587 (message):
Imported targets and dependency information not available for Boost version
(all versions older than 1.33)
Call Stack (most recent call first):
C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake:950 (_Boost_COMPONENT_DEPENDENCIES)
C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake:1618 (_Boost_MISSING_DEPENDENCIES)
CMakeLists.txt:44 (find_package)
CMake Warning at C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake:587 (message):
Imported targets and dependency information not available for Boost version
(all versions older than 1.33)
Call Stack (most recent call first):
C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake:950 (_Boost_COMPONENT_DEPENDENCIES)
C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake:1618 (_Boost_MISSING_DEPENDENCIES)
CMakeLists.txt:44 (find_package)
CMake Warning at C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake:587 (message):
Imported targets and dependency information not available for Boost version
(all versions older than 1.33)
Call Stack (most recent call first):
C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake:950 (_Boost_COMPONENT_DEPENDENCIES)
C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake:1618 (_Boost_MISSING_DEPENDENCIES)
CMakeLists.txt:44 (find_package)
CMake Warning at C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake:587 (message):
Imported targets and dependency information not available for Boost version
(all versions older than 1.33)
Call Stack (most recent call first):
C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake:950 (_Boost_COMPONENT_DEPENDENCIES)
C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake:1618 (_Boost_MISSING_DEPENDENCIES)
CMakeLists.txt:44 (find_package)
CMake Warning at C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake:587 (message):
Imported targets and dependency information not available for Boost version
(all versions older than 1.33)
Call Stack (most recent call first):
C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake:950 (_Boost_COMPONENT_DEPENDENCIES)
C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake:1618 (_Boost_MISSING_DEPENDENCIES)
CMakeLists.txt:44 (find_package)
CMake Warning at C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake:587 (message):
Imported targets and dependency information not available for Boost version
(all versions older than 1.33)
Call Stack (most recent call first):
C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake:950 (_Boost_COMPONENT_DEPENDENCIES)
C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake:1618 (_Boost_MISSING_DEPENDENCIES)
CMakeLists.txt:44 (find_package)
CMake Error at C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/FindBoost.cmake:2044 (message):
Unable to find the requested Boost libraries.
Unable to find the Boost header files. Please set BOOST_ROOT to the root
directory containing Boost or BOOST_INCLUDEDIR to the directory containing
Boost's headers.
Call Stack (most recent call first):
CMakeLists.txt:44 (find_package)
CMake Error at CMakeLists.txt:46 (find_package):
Could not find a package configuration file provided by "ZeroMQ" with any
of the following names:
ZeroMQConfig.cmake
zeromq-config.cmake
Add the installation prefix of "ZeroMQ" to CMAKE_PREFIX_PATH or set
"ZeroMQ_DIR" to a directory containing one of the above files. If "ZeroMQ"
provides a separate development package or SDK, be sure it has been
installed.
In particular, the command line:
Command line: C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2017\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe -G "Ninja" -DCMAKE_INSTALL_PREFIX:PATH="C:\Users\me\CMakeBuilds\55e700de-d370-f634-bc40-455cedaf329e\install\x86-Debug" -DCMAKE_CXX_COMPILER="C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.14.26428/bin/HostX86/x86/cl.exe" -DCMAKE_C_COMPILER="C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.14.26428/bin/HostX86/x86/cl.exe" -DCMAKE_TOOLCHAIN_FILE=C:/Users/me/source/repos/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_BUILD_TYPE="Debug" -DCMAKE_MAKE_PROGRAM="C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2017\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" "C:\Users\me\Source\Repos\bluezero"
does contain the -DCMAKE_TOOLCHAIN_FILE=C:/Users/me/source/repos/vcpkg/scripts/buildsystems/vcpkg.cmake as it should be, but apparently this is not enough.
The relevant section of the CMakeLists.txt file about finding dependencies is:
if(WIN32)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
add_definitions(-DBOOST_ALL_NO_LIB)
add_definitions(-DWIN32_LEAN_AND_MEAN)
add_definitions(-DBOOST_USE_WINDOWS_H)
add_definitions(-DNOMINMAX)
endif()
find_package(Doxygen)
find_package(Boost 1.54 REQUIRED COMPONENTS thread system regex timer filesystem serialization)
if(WIN32)
find_package(ZeroMQ CONFIG REQUIRED)
else()
find_package(ZMQ 4.1.4 REQUIRED)
endif()
find_package(ZLIB)
find_package(LZ4)
Am I making some obvious mistake?
I had same issue so I switched to command line for running project on windows with vscode and it runs perfectly.Issue for visual studio is that vcpkg install 32bit version and visual studio is looking for x64 version of library, So simply force it vcpkg to install x64 version instead like following example:
vcpkg install <Your library>:x64-windows
You can also run your project in visual studio code with the command line using the following commands:
cmake . -GNinja -DCMAKE_TOOLCHAIN_FILE=<VCPKG installed folder>/vcpkg/scripts/buildsystems/vcpkg.cmake
After that run:
ninja
And then run your project.
Because this command works but its equivalent does not work on visual studio, I guess it's visual studio bug.
Related
I'm trying to play around with OpenCV and OpenCV Face (a contrib module). Unfortunately I'm bound to a Windows devivce. Furhermore the OpenCV Windows download does not contain the contrib modules e.g. the face one which I need, so I tried to build OpenCV with OpenCV contrib myself. The project itself should run on Windows & Linux.
If I use the prebuild OpenCV files (except the face module), everything works just fine.
Windows specs:
CMake file
cmake_minimum_required(VERSION 3.24)
project(smart_mirror)
set(CMAKE_CXX_STANDARD 23)
include(FetchContent)
add_compile_definitions(JM_DEBUG_MODE=true)
# Add the main target
add_executable(smart_mirror main.cpp src/CameraDevice.cpp "src/VideoProcessor.h" "src/MotionVideoProcessor.cpp" "src/FaceRecognitionVideoProcessor.cpp" "src/FaceDetectorVideoProcessor.cpp")
find_package(OpenCV REQUIRED)
find_package(Qt6 REQUIRED COMPONENTS Core WebSockets)
FetchContent_Declare(
spdlog
GIT_REPOSITORY https://github.com/gabime/spdlog.git
GIT_TAG v1.11.0
FIND_PACKAGE_ARGS
)
FetchContent_MakeAvailable(spdlog)
# Add the OpenCV include directories to the main target
target_include_directories(smart_mirror PRIVATE ${OpenCV_INCLUDE_DIRS})
# Link the main target with OpenCV
target_link_libraries(smart_mirror ${OpenCV_LIBS} spdlog Qt6::Core Qt6::WebSockets)
message(STATUS "Add libs: ${OpenCV_LIBS} and includes: ${OpenCV_INCLUDE_DIRS}")
Project CMake configure (contains a line with all OpenCV_LIBS printed as STATUS message for debugging)
1> CMake generation started for default configuration: 'x64-Debug'.
1> Command line: "C:\WINDOWS\system32\cmd.exe" /c "%SYSTEMROOT%\System32\chcp.com 65001 >NUL && "C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\2022\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe" -G "Ninja" -DCMAKE_BUILD_TYPE:STRING="Debug" -DCMAKE_INSTALL_PREFIX:PATH="Y:\smart-mirror\out\install\x64-Debug" -DCMAKE_C_COMPILER:FILEPATH="C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.34.31933/bin/Hostx64/x64/cl.exe" -DCMAKE_CXX_COMPILER:FILEPATH="C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.34.31933/bin/Hostx64/x64/cl.exe" -DCMAKE_MAKE_PROGRAM="C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\2022\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" "Y:\smart-mirror" 2>&1"
1> Working directory: Y:\smart-mirror\out\build\x64-Debug
1> [CMake] -- The C compiler identification is MSVC 19.34.31937.0
1> [CMake] -- The CXX compiler identification is MSVC 19.34.31937.0
1> [CMake] -- Detecting C compiler ABI info
1> [CMake] -- Detecting C compiler ABI info - done
1> [CMake] -- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.34.31933/bin/Hostx64/x64/cl.exe - skipped
1> [CMake] -- Detecting C compile features
1> [CMake] -- Detecting C compile features - done
1> [CMake] -- Detecting CXX compiler ABI info
1> [CMake] -- Detecting CXX compiler ABI info - done
1> [CMake] -- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.34.31933/bin/Hostx64/x64/cl.exe - skipped
1> [CMake] -- Detecting CXX compile features
1> [CMake] -- Detecting CXX compile features - done
1> [CMake] -- Found OpenCV: C:/opencv (found version "4.7.0")
1> [CMake] -- Performing Test CMAKE_HAVE_LIBC_PTHREAD
1> [CMake] -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
1> [CMake] -- Looking for pthread_create in pthreads
1> [CMake] -- Looking for pthread_create in pthreads - not found
1> [CMake] -- Looking for pthread_create in pthread
1> [CMake] -- Looking for pthread_create in pthread - not found
1> [CMake] -- Found Threads: TRUE
1> [CMake] -- Performing Test HAVE_STDATOMIC
1> [CMake] -- Performing Test HAVE_STDATOMIC - Success
1> [CMake] -- Found WrapAtomic: TRUE
1> [CMake] -- Build spdlog: 1.11.0
1> [CMake] -- Build type: Debug
1> [CMake] -- Add libs: opencv_calib3d;opencv_core;opencv_dnn;opencv_features2d;opencv_flann;opencv_gapi;opencv_highgui;opencv_imgcodecs;opencv_imgproc;opencv_ml;opencv_objdetect;opencv_photo;opencv_stitching;opencv_video;opencv_videoio;opencv_aruco;opencv_barcode;opencv_bgsegm;opencv_bioinspired;opencv_ccalib;opencv_cvv;opencv_datasets;opencv_dnn_objdetect;opencv_dnn_superres;opencv_dpm;opencv_face;opencv_fuzzy;opencv_hfs;opencv_img_hash;opencv_intensity_transform;opencv_line_descriptor;opencv_mcc;opencv_optflow;opencv_phase_unwrapping;opencv_plot;opencv_quality;opencv_rapid;opencv_reg;opencv_rgbd;opencv_saliency;opencv_shape;opencv_stereo;opencv_structured_light;opencv_superres;opencv_surface_matching;opencv_text;opencv_tracking;opencv_videostab;opencv_wechat_qrcode;opencv_xfeatures2d;opencv_ximgproc;opencv_xobjdetect;opencv_xphoto and includes: C:/opencv/include
1> [CMake] -- Configuring done
1> [CMake] -- Generating done
1> [CMake] -- Build files have been written to: Y:/smart-mirror/out/build/x64-Debug
1> Extracted CMake variables.
1> Extracted source files and headers.
1> Extracted code model.
1> Extracted toolchain configurations.
1> Extracted includes paths.
1> CMake generation finished.
CMake build command respectively with and without -DBUILD_opencv_world
cmake -B "build" -G "Visual Studio 17 2022" -A x64 -DCMAKE_BUILD_TYPE=RELEASE -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DOPENCV_GENERATE_PKGCONFIG=ON -DWITH_OPENGL=ON -DWITH_QT=ON -DBUILD_opencv_python2=OFF -DBUILD_opencv_python3=ON -DBUILD_JAVA=OFF -DBUILD_FAT_JAVA_LIB=OFF -DBUILD_DOCS=OFF -DVIDEOIO_PLUGIN_LIST=all -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules -DBUILD_EXAMPLES=OFF .
I encountered two error cases depending on the CMake settings
1. BUILD_opencv_world=ON
If I run cmake --build build --config Release to build the libs it stops kind of after building opencv_world. If I open the Visual Studio solution to build I get error messages related to opencv_world
Error output (cmake --build runs until the very first marked line and stop without any output, so first I thought everything built without error)
Error list
2. -DBUILD_opencv_world=OFF
Because I rooted the build issue cause at the opencv_world module (which normally comes with the prebuild binaries), I tried to build without them. This build works but then I get undefined reference error of the linker.
Linker error in Visual Studio while building my project
Edit
I also tried the combi ninja + clang but also no luck. Here it fails even earlier
Ninja + clang fail
I'm having trouble configuring/building czmq with CMake. This is the current project structure with the three libraries' source under "extlibs":
root
|--CMakeLists.txt
|--src
|--include
|--extlibs
| |--CMakeLists.txt
| |--sodium
| |--zmq
| |--czmq
The root CMakeLists.txt:
cmake_minimum_required (VERSION 3.15)
set(project czmq_build_project)
set(project_root ${CMAKE_CURRENT_SOURCE_DIR})
set(extlibs ${project_root}/extlibs)
set(msbuild "C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/MSBuild/Current/Bin/MSBuild.exe")
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED on)
set(project_cfg Release)
project(${project} CXX)
# Add source
add_executable (${project} "src/main.cpp" "include/class.hpp")
# Directories to search for headers -----------
include_directories(${extlibs})
include_directories(${project_root}/include)
# Add 3rd Party Libraries
add_subdirectory(${extlibs})
And the "extlibs/CMakeLists.txt"
# ----------------------------------------------
# Third Party Libraries
# Note: All libraries are being built under a
# static release config for x64 (at the moment)
# ----------------------------------------------
# czmq requires libzmq. Additionaly, libsodium is
# used for the curve encryption library for libzmq.
# Therefore, we build: libsodium->libzmq->czmq.
# ----------------------------------------------
include(ExternalProject)
set(lib_out "${CMAKE_BINARY_DIR}/extlibs")
add_custom_target(buildsodium ALL)
# Configure libsodium -------------------------
function(build_libsodium)
set(sodium_root "${extlibs}/sodium")
set(sodium_sln "${sodium_root}/builds/msvc/vs2019/libsodium.sln")
set(sodium_bin "${sodium_root}/bin")
set(sodium_lib "${sodium_root}/bin/x64/${project_cfg}/v142/static/libsodium.lib")
set(sodium_out "${lib_out}/sodium/libsodium.lib")
set(sodium_bldcmd ${msbuild} -m -t:Build -p:configuration=Static${project_cfg} -p:platform=x64 ${sodium_sln})
ExternalProject_Add(libsodium
SOURCE_DIR "${sodium_root}"
CONFIGURE_COMMAND ""
BUILD_COMMAND ${sodium_bldcmd}
INSTALL_COMMAND ""
ALWAYS TRUE
)
add_custom_command(TARGET libsodium POST_BUILD
BYPRODUCTS ${sodium_out}
COMMAND echo "Copying libsodium.lib to ${sodium_out}"
COMMAND ${CMAKE_COMMAND} -E copy ${sodium_lib} ${sodium_out}
COMMAND echo "Removing ${sodium_bin}"
COMMAND ${CMAKE_COMMAND} -E remove_directory ${sodium_bin}
)
add_dependencies(buildsodium libsodium)
endfunction()
add_custom_target(buildzmq ALL)
# Configure libzmq ----------------------------
function(build_libzmq)
set(ENABLE_CURVE OFF )
set(WITH_LIBSODIUM_STATIC ON)
set(ENABLE_CPACK OFF)
set(BUILD_SHARED OFF)
set(BUILD_STATIC ON)
set(BUILD_TESTS OFF)
set(CMAKE_INCLUDE_PATH ${extlibs}/sodium/src/libsodium/include)
set(CMAKE_LIBRARY_PATH ${lib_out}/sodium)
set(CMAKE_CXX_FLAGS_RELEASE "/MT /O2 /Ob2 /DNDEBUG")
set(CMAKE_CXX_FLAGS_DEBUG "/MTd /Zi /Ob0 /Od /RTC1")
set(CMAKE_INSTALL_PREFIX ${lib_out}/zmq)
add_subdirectory(zmq)
add_dependencies(buildzmq buildsodium)
endfunction()
add_custom_target(buildczmq ALL)
# Configure czmq ------------------------------
function(build_libczmq)
set(ZeroMQ_DIR ${lib_out}/zmq/lib)
set(CZMQ_BUILD_SHARED OFF)
set(CZMQ_BUILD_STATIC ON)
set(BUILD_TESTING OFF)
set(CMAKE_PREFIX_PATH ${lib_out}/zmq)
set(LIBZMQ_INCLUDE_DIRS ${extlibs}/zmq/include)
set(LIBZMQ_LIBRARIES ${lib_out}/zmq/lib)
set(CMAKE_CXX_FLAGS_RELEASE "-DZMQ_STATIC /MT /O2 /Ob2 /DNDEBUG")
set(CMAKE_CXX_FLAGS_DEBUG "-DZMQ_STATIC /MTd /Zi /Ob0 /Od /RTC1")
set(CMAKE_CONFIGURATION_TYPES "Debug;Release")
set(CMAKE_INSTALL_PREFIX ${lib_out}/czmq)
add_subdirectory(czmq)
add_dependencies(buildczmq buildzmq)
endfunction()
build_libsodium()
build_libzmq()
build_libczmq()
CMake output:
CMake generation started for configuration: 'x64'.
1> Working directory: ...<root>\build\x64
1> [CMake] -- Detected ZMQ Version - 4.3.4
1> [CMake] -- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE)
1> [CMake] -- Not building draft classes and methods
1> [CMake] -- Using builtin sha1
1> [CMake] -- CURVE security is disabled
1> [CMake] -- Detected _WIN32_WINNT from CMAKE_SYSTEM_VERSION: 0x0A00
1> [CMake] -- Using polling method in I/O threads: epoll
1> [CMake] -- Including wepoll
1> [CMake] -- Using polling method in zmq_poll(er)_* API: poll
1> [CMake] -- Using 64 bytes alignment for lock-free data structures
1> [CMake] -- Using condition_variable_t implementation: stl11
1> [CMake] -- Checking whether noexcept is supported
1> [CMake] -- Could NOT find AsciiDoc (missing: ASCIIDOC_EXECUTABLE)
1> [CMake] CMake Deprecation Warning at extlibs/zmq/tests/CMakeLists.txt:2 (cmake_minimum_required):
1> [CMake] Compatibility with CMake < 2.8.12 will be removed from a future version of
1> [CMake] CMake.
1> [CMake]
1> [CMake] Update the VERSION argument <min> value or use a ...<max> suffix to tell
1> [CMake] CMake that the project does not need compatibility with older versions.
1> [CMake]
1> [CMake]
1> [CMake] CMake Warning (dev) at extlibs/zmq/tests/CMakeLists.txt:306 (message):
1> [CMake] Test 'test_bind_stream_fuzzer' is not known to CTest.
1> [CMake] This warning is for project developers. Use -Wno-dev to suppress it.
1> [CMake]
1> [CMake] CMake Warning (dev) at extlibs/zmq/tests/CMakeLists.txt:306 (message):
1> [CMake] Test 'test_bind_ws_fuzzer' is not known to CTest.
1> [CMake] This warning is for project developers. Use -Wno-dev to suppress it.
1> [CMake]
1> [CMake] CMake Warning (dev) at extlibs/zmq/tests/CMakeLists.txt:306 (message):
1> [CMake] Test 'test_connect_stream_fuzzer' is not known to CTest.
1> [CMake] This warning is for project developers. Use -Wno-dev to suppress it.
1> [CMake]
1> [CMake] CMake Warning (dev) at extlibs/zmq/tests/CMakeLists.txt:306 (message):
1> [CMake] Test 'test_connect_ws_fuzzer' is not known to CTest.
1> [CMake] This warning is for project developers. Use -Wno-dev to suppress it.
1> [CMake]
1> [CMake] CMake Warning (dev) at extlibs/zmq/tests/CMakeLists.txt:306 (message):
1> [CMake] Test 'test_socket_options_fuzzer' is not known to CTest.
1> [CMake] This warning is for project developers. Use -Wno-dev to suppress it.
1> [CMake]
1> [CMake] CMake Deprecation Warning at extlibs/zmq/unittests/CMakeLists.txt:2 (cmake_minimum_required):
1> [CMake] Compatibility with CMake < 2.8.12 will be removed from a future version of
1> [CMake] CMake.
1> [CMake]
1> [CMake] Update the VERSION argument <min> value or use a ...<max> suffix to tell
1> [CMake] CMake that the project does not need compatibility with older versions.
1> [CMake]
1> [CMake]
1> [CMake] CMake Warning (dev) at C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.19/Modules/FindPackageHandleStandardArgs.cmake:426 (message):
1> [CMake] The package name passed to `find_package_handle_standard_args` (LIBZMQ)
1> [CMake] does not match the name of the calling package (libzmq). This can lead to
1> [CMake] problems in calling code that expects `find_package` result variables
1> [CMake] (e.g., `_FOUND`) to follow a certain pattern.
1> [CMake] Call Stack (most recent call first):
1> [CMake] extlibs/czmq/Findlibzmq.cmake:83 (find_package_handle_standard_args)
1> [CMake] extlibs/czmq/CMakeLists.txt:133 (find_package)
1> [CMake] This warning is for project developers. Use -Wno-dev to suppress it.
1> [CMake] -- Could NOT find LIBZMQ (missing: LIBZMQ_LIBRARIES)
1> [CMake] CMake Error at extlibs/czmq/CMakeLists.txt:144 (message):
1> [CMake] libzmq not found.
1> [CMake]
1> [CMake]
1> [CMake] -- Configuring incomplete, errors occurred!
1> [CMake] See also "<root>/build/x64/CMakeFiles/CMakeOutput.log".
1> [CMake] See also "<root>/build/x64/CMakeFiles/CMakeError.log".
The sodium and zmq functions work correctly but czmq does not. Since I am building the libzmq library, I do not have the .lib at configuration time when calling CMake, so czmq complains about not being able to find libzmq.
I have each library installing to "root/build/x64/extlibs/". I have tried a custom target dependency structure but am having no luck with getting czmq to be okay with not seeing the .lib at config time. What can I try to make this work? Thanks!
I suggest that you switch to the conan package manager
https://conan.io/center/libsodium
You can find an example here: https://github.com/damian123/crypto
I'm trying to use CMake with Visual Studio for a 3D class, but whenever I open the provided CMake project, Visual Studio can't generate CMake files. I get the following error (some parts of the output were in French so I translated them):
CMake generation started with the default configuration: 'x64-Debug (par défaut)'.
1> Command line: "cmd.exe" /c ""c:\program files (x86)\microsoft visual studio\2019\community\common7\ide\commonextensions\microsoft\cmake\CMake\bin\cmake.exe" -G "Ninja" -DCMAKE_INSTALL_PREFIX:PATH="D:\Scolaire\11 - 2A\INF443\1 - Tutoriels\create_window_commented\out\install\x64-Debug (par défaut)" -DCMAKE_C_COMPILER:FILEPATH="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.26.28801/bin/HostX64/x64/cl.exe" -DCMAKE_CXX_COMPILER:FILEPATH="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.26.28801/bin/HostX64/x64/cl.exe" -DCMAKE_BUILD_TYPE="Debug" -DCMAKE_MAKE_PROGRAM="c:\program files (x86)\microsoft visual studio\2019\community\common7\ide\commonextensions\microsoft\cmake\Ninja\ninja.exe" "D:\Scolaire\11 - 2A\INF443\1 - Tutoriels\create_window_commented" 2>&1"
1> Working directory: D:\Scolaire\11 - 2A\INF443\1 - Tutoriels\create_window_commented\out\build\x64-Debug (par défaut)
1> [CMake] -- The C compiler identification is MSVC 19.26.28805.0
1> [CMake] -- The CXX compiler identification is MSVC 19.26.28805.0
1> [CMake] -- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.26.28801/bin/HostX64/x64/cl.exe
1> [CMake] -- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.26.28801/bin/HostX64/x64/cl.exe - broken
1> [CMake] CMake Error at C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.17/Modules/CMakeTestCCompiler.cmake:60 (message):
1> [CMake] The C compiler
1> [CMake]
1> [CMake] "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.26.28801/bin/HostX64/x64/cl.exe"
1> [CMake]
1> [CMake] is not able to compile a simple test program.
1> [CMake]
1> [CMake] It fails with the following output:
1> [CMake]
1> [CMake] Change Dir: D:/Scolaire/11 - 2A/INF443/1 - Tutoriels/create_window_commented/out/build/x64-Debug (par défaut)/CMakeFiles/CMakeTmp
1> [CMake]
1> [CMake] Run Build Command(s):C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/Ninja/ninja.exe cmTC_cbae0 && [1/2] Building C object CMakeFiles\cmTC_cbae0.dir\testCCompiler.c.obj
1> [CMake] [2/2] Linking C executable cmTC_cbae0.exe
1> [CMake] FAILED: cmTC_cbae0.exe
1> [CMake] cmd.exe /C "cd . && "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\cmTC_cbae0.dir --rc=rc --mt=CMAKE_MT-NOTFOUND --manifests -- C:\PROGRA~2\MICROS~1\2019\COMMUN~1\VC\Tools\MSVC\1426~1.288\bin\Hostx64\x64\link.exe /nologo CMakeFiles\cmTC_cbae0.dir\testCCompiler.c.obj /out:cmTC_cbae0.exe /implib:cmTC_cbae0.lib /pdb:cmTC_cbae0.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."
1> [CMake] RC Pass 1: command "rc /fo CMakeFiles\cmTC_cbae0.dir/manifest.res CMakeFiles\cmTC_cbae0.dir/manifest.rc" failed (exit code 0) with the following output:
1> [CMake] The specified file could not be found
1> [CMake] ninja: build stopped: subcommand failed.
1> [CMake]
1> [CMake]
1> [CMake]
1> [CMake]
1> [CMake]
1> [CMake] CMake will not be able to correctly generate this project.
1> [CMake] Call Stack (most recent call first):
1> [CMake] CMakeLists.txt:3 (project)
1> [CMake] -- Configuring incomplete, errors occurred!
1> [CMake] See also "D:/Scolaire/11 - 2A/INF443/1 - Tutoriels/create_window_commented/out/build/x64-Debug (par défaut)/CMakeFiles/CMakeOutput.log".
1> [CMake] See also "D:/Scolaire/11 - 2A/INF443/1 - Tutoriels/create_window_commented/out/build/x64-Debug (par défaut)/CMakeFiles/CMakeError.log".
1> Execution failed 'cmd.exe' '/c ""c:\program files (x86)\microsoft visual studio\2019\community\common7\ide\commonextensions\microsoft\cmake\CMake\bin\cmake.exe" -G "Ninja" -DCMAKE_INSTALL_PREFIX:PATH="D:\Scolaire\11 - 2A\INF443\1 - Tutoriels\create_window_commented\out\install\x64-Debug (par défaut)" -DCMAKE_C_COMPILER:FILEPATH="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.26.28801/bin/HostX64/x64/cl.exe" -DCMAKE_CXX_COMPILER:FILEPATH="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.26.28801/bin/HostX64/x64/cl.exe" -DCMAKE_BUILD_TYPE="Debug" -DCMAKE_MAKE_PROGRAM="c:\program files (x86)\microsoft visual studio\2019\community\common7\ide\commonextensions\microsoft\cmake\Ninja\ninja.exe" "D:\Scolaire\11 - 2A\INF443\1 - Tutoriels\create_window_commented" 2>&1"'. Error: ''cmd.exe' '/c ""c:\program files (x86)\microsoft visual studio\2019\community\common7\ide\commonextensions\microsoft\cmake\CMake\bin\cmake.exe" -G "Ninja" -DCMAKE_INSTALL_PREFIX:PATH="D:\Scolaire\11 - 2A\INF443\1 - Tutoriels\create_window_commented\out\install\x64-Debug (par défaut)" -DCMAKE_C_COMPILER:FILEPATH="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.26.28801/bin/HostX64/x64/cl.exe" -DCMAKE_CXX_COMPILER:FILEPATH="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.26.28801/bin/HostX64/x64/cl.exe" -DCMAKE_BUILD_TYPE="Debug" -DCMAKE_MAKE_PROGRAM="c:\program files (x86)\microsoft visual studio\2019\community\common7\ide\commonextensions\microsoft\cmake\Ninja\ninja.exe" "D:\Scolaire\11 - 2A\INF443\1 - Tutoriels\create_window_commented" 2>&1"' was returned with end code: 1'.
Other people in my class are using the same provided files and don't have errors so the problem can't be from this. I use Windows 10 and the latest version of Visual Studio (I tried to uninstall and reinstall it). The C++ and CMake tools are installed within Visual Studio.
The provided project should only open an empty windows, it looks like this:
PS D:\Scolaire\11 - 2A\INF443\1 - Tutoriels\create_window_commented> ls
Répertoire : D:\Scolaire\11 - 2A\INF443\1 - Tutoriels\create_window_commented
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 25/05/2020 14:09 .vs
d----- 25/05/2020 14:09 out
d----- 03/08/2018 15:10 src
-a---- 11/03/2020 08:59 175 CMakeLists.txt
-a---- 02/03/2020 17:37 214 Makefile
-a---- 02/03/2020 17:37 229 meson.build
-a---- 11/03/2020 08:59 847 README
Do you know what the cause could be ? Thanks!
The problem was from the CMakeLists.txt, the parameters inside this file were for Unix instead of Windows.
Edit: the CMakeLists.txt that didn't work was this:
cmake_minimum_required(VERSION 2.8)
project(pgm)
set(CMAKE_CXX_FLAGS "-O2 -g -std=c++11 -Wall -Wextra")
add_executable(pgm src/main.cpp)
target_link_libraries(pgm glfw)
I made the following changes.
From set(CMAKE_CXX_FLAGS "-O2 -g -std=c++11 -Wall -Wextra") to:
set(CMAKE_BUILD_TYPE Debug)
set(GLFW_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/lib_windows/glfw3_win/include")
include_directories(${GLFW_INCLUDE_DIRS})
set(GLFW_LIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/lib_windows/glfw3_win/lib/glfw3.lib") # Set directory to precompiled version of glfw3
From target_link_libraries(pgm glfw) to:
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${source_files}) # Allow to explore source directories as a tree
target_link_libraries(pgm ${GLFW_LIBRARIES})
I didn't write this code, I just understood that the wrong lines of code were meant for Unix so I replaced them with the right lines of code from another CMakeLists.txt from a similar provided OpenGL project.
My solution — add this right before 'project' in top cmake file:
set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY")
I'm trying to compile a simple app to test a few libraries I might be using in the future. Because of some problems I had with msvc I tried Clang, which made a strange error I got disappear.
The problem I have now is that the libraries I want to test use OpenMP. They import it using the FindOpenMP module CMake privides. However the module doesn't find it with Clang.
cmake_minimum_required(VERSION 3.14.0)
project(blaze-test VERSION 0.1.0)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(OpenMP)
I got this output :
1> CMake generation started for configuration: 'x64-Debug'.
1> Environment settings:
1> CXXFLAGS=-m64 -fdiagnostics-absolute-paths
1> CFLAGS=-m64 -fdiagnostics-absolute-paths
1> Command line: "cmd.exe" /c ""C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe" -G "Ninja" -DCMAKE_INSTALL_PREFIX:PATH="PATH\blaze-test\install\x64-Debug" -DCMAKE_CXX_COMPILER:FILEPATH="C:/PROGRAM FILES (X86)/MICROSOFT VISUAL STUDIO/2019/COMMUNITY/VC/Tools/Llvm/8.0.0/bin/clang-cl.exe" -DCMAKE_C_COMPILER:FILEPATH="C:/PROGRAM FILES (X86)/MICROSOFT VISUAL STUDIO/2019/COMMUNITY/VC/Tools/Llvm/8.0.0/bin/clang-cl.exe" -DCMAKE_BUILD_TYPE="Debug" -DCMAKE_MAKE_PROGRAM="C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" "PATH\blaze-test" 2>&1"
1> Working directory: PATH\blaze-test\build\x64-Debug
1> [CMake] -- The C compiler identification is Clang 8.0.0
1> [CMake] -- The CXX compiler identification is Clang 8.0.0
1> [CMake] -- Check for working C compiler: C:/PROGRAM FILES (X86)/MICROSOFT VISUAL STUDIO/2019/COMMUNITY/VC/Tools/Llvm/8.0.0/bin/clang-cl.exe
1> [CMake] -- Check for working C compiler: C:/PROGRAM FILES (X86)/MICROSOFT VISUAL STUDIO/2019/COMMUNITY/VC/Tools/Llvm/8.0.0/bin/clang-cl.exe -- works
1> [CMake] -- Detecting C compiler ABI info
1> [CMake] -- Detecting C compiler ABI info - done
1> [CMake] -- Detecting C compile features
1> [CMake] -- Detecting C compile features - done
1> [CMake] -- Check for working CXX compiler: C:/PROGRAM FILES (X86)/MICROSOFT VISUAL STUDIO/2019/COMMUNITY/VC/Tools/Llvm/8.0.0/bin/clang-cl.exe
1> [CMake] -- Check for working CXX compiler: C:/PROGRAM FILES (X86)/MICROSOFT VISUAL STUDIO/2019/COMMUNITY/VC/Tools/Llvm/8.0.0/bin/clang-cl.exe -- works
1> [CMake] -- Detecting CXX compiler ABI info
1> [CMake] -- Detecting CXX compiler ABI info - done
1> [CMake] -- Detecting CXX compile features
1> [CMake] -- Detecting CXX compile features - done
1> [CMake] -- Could NOT find OpenMP_C (missing: OpenMP_C_FLAGS OpenMP_C_LIB_NAMES)
1> [CMake] -- Could NOT find OpenMP_CXX (missing: OpenMP_CXX_FLAGS OpenMP_CXX_LIB_NAMES)
1> [CMake] -- Could NOT find OpenMP (missing: OpenMP_C_FOUND OpenMP_CXX_FOUND)
Based on this I added
set(OpenMP_CXX_FLAGS "-Xclang -fopenmp" CACHE STRING "" FORCE)
set(OpenMP_C_FLAGS "-Xclang -fopenmp" CACHE STRING "" FORCE)
right before the find_package call. It removed the part about the compiler flags from the error message. I added libomp.lib the same way. Then I get
1> [CMake] -- Could NOT find OpenMP_C (missing: OpenMP_C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/Llvm/8.0.0/lib/libomp.lib_LIBRARY)
1> [CMake] -- Could NOT find OpenMP_CXX (missing: OpenMP_C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/Llvm/8.0.0/lib/libomp.lib_LIBRARY)
1> [CMake] -- Could NOT find OpenMP (missing: OpenMP_C_FOUND OpenMP_CXX_FOUND)
I hope someone can tell me how to get CMake to find it. These unreliable Find Modules are really annoying.
ps: I'm using Clang 8 (clang-cl.exe) with CMake 3.14 and Visual Studio 2019.
When using find_package(OpenMP REQUIRED), I have also received similar errors when using clang-cl from Visual Studio. There are known limitations with CMake's FindOpenMP.cmake module, as well as some lack of support the clang-cl side. There are other answers on this site suggesting to populate the CMake OpenMP_ variables manually, but this seems backwards. When I tried it, CMake claimed that OpenMP was FOUND, but the paths to the libraries was still unknown and compilation was unsuccessful. I was able to successfully run CMake then compile my applications with MSVC+Clang by avoiding the use of find_package and (unfortunately) hard-coding the path to the OpenMP libraries for now:
cmake_minimum_required(VERSION 3.14.0)
project(blaze-test VERSION 0.1.0)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(OpenMP_LIBRARY_DIR "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/Llvm/lib")
set(OpenMP_CXX_FLAGS "-Xclang -fopenmp")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
# Tell CMake where to find the OpenMP libraries.
link_directories(${OpenMP_LIBRARY_DIR})
# Library
add_library(MyLibrary SHARED MyExample.h MyExample.cpp)
# Link in the OpenMP libraries.
target_link_libraries(MyLibrary PUBLIC libomp libiomp5md)
# Executable
add_executable(MyOpenMpTest MyOpenMpTest .cpp)
target_link_libraries(MyOpenMpTest MyLibrary)
Hopefully, the folks at CMake and LLVM will get this issue worked out soon and FindOpenMP.cmake can be used more reliably.
I am trying to add Boost to a C++ application using CMake. I have read through all relevant questions I can find on SO, and I feel I am getting closer to a solution. But the CMake still can't find the requested Boost library for some reasons.
I am trying to find "boost_filesystem". The debug shows CMake is looking for "boost_filesystem-vc141-mt-gd-1_65_1". I do have the file "libboost_filesystem-vc141-mt-gd-1_65_1.lib" in the folder "C:\boost\boost_1_65_1\stage\lib". I suppose this is the file CMake is looking for, but for some reasons CMake says it can't find it.
Here is the procedure I used to build the Boost. This may be too much details for most people but I suspect it may be helpful to another newbie.
download and extract Boost 1.65.1 in folder C:\boost\boost_1_65_1
go to developer prompt command line and run bootstrap.bat under the above folder.
updated file visualc.hpp under C:\boost\boost_1_65_1\boost\config\compiler (see Unknown compiler version while compiling Boost with MSVC 14.0 (VS 2015)!
Replaced the lines in the bottom of the file visualc.hpp :
// last known and checked version is 19.11.25506 (VC++ 2017.3):
#if (_MSC_VER > 1911)
with
// last known and checked version is 19.13.26128 (VC++ 2017.5.6):
#if (_MSC_VER > 1913)
Open another file project-config.jam under the folder boost_1_65_1 and updated the second line to the following:
using msvc : 14.1 : "C:\Program Files (x86)\Microsoft Visual Studio\2017
\Professional\VC\Tools\MSVC\14.13.26128\bin\Hostx64\x64\cl.exe" ;
Go back to developer prompt command line and run the following to build Boost:
b2 toolset=msvc-14.1 address-model=64
It seems I have done the following items correctly:
properly built the libraries, though not using the default directory. I confirmed that the requested library is built.
assigned the path correctly to the CMake designated directories
used CMake find_package() correctly
Here are the relevant versions I am using:
VS: 2017 v15.6.1 with CMake 3.10
Boost version: 1.65.1, built with tool MSVC 14.1
Here is the CMakelist.txt:
cmake_minimum_required(VERSION 3.6 FATAL_ERROR)
project(test)
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
set(Boost_DEBUG ON)
set(BOOST_ROOT C:\\boost\\boost_1_65_1)
set(BOOST_INCLUDEDIR C:\\boost\\boost_1_65_1)
set(BOOST_LIBRARYDIR C:\\boost\\boost_1_65_1\\stage\\lib)
set(Boost_DEBUG 1)
find_package(Boost COMPONENTS filesystem REQUIRED)
message(STATUS "Boost LIBRARIES: " ${Boost_LIBRARIES})
add_executable(test_Boost main.cpp)
target_link_libraries(test_Boost ${Boost_LIBRARIES})
here is part of the output that may be relevant:
1> Command line: C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2017\PROFESSIONAL\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe -G "Ninja" -DCMAKE_INSTALL_PREFIX:PATH="C:\Users\david\CMakeBuilds\94321a3b-9fa8-083f-a86f-e151c3abae79\install\x64-Release" -DCMAKE_CXX_COMPILER="C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.13.26128/bin/HostX64/x64/cl.exe" -DCMAKE_C_COMPILER="C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.13.26128/bin/HostX64/x64/cl.exe" -DCMAKE_BUILD_TYPE="RelWithDebInfo" -DCMAKE_MAKE_PROGRAM="C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2017\PROFESSIONAL\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" "E:\computer\boost\cmake"
1> Working directory: C:\Users\david\CMakeBuilds\94321a3b-9fa8-083f-a86f-e151c3abae79\build\x64-Release
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1073 ] _boost_TEST_VERSIONS = 1.65.1;1.65.0;1.65;1.64.0
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1075 ] Boost_USE_MULTITHREADED = ON
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1077 ] Boost_USE_STATIC_LIBS = OFF
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1079 ] Boost_USE_STATIC_RUNTIME = OFF
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1081 ] Boost_ADDITIONAL_VERSIONS =
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1083 ] Boost_NO_SYSTEM_PATHS =
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1151 ] Declared as CMake or Environmental Variables:
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1153 ] BOOST_ROOT = C:\boost\boost_1_65_1
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1155 ] BOOST_INCLUDEDIR = C:\boost\boost_1_65_1
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1157 ] BOOST_LIBRARYDIR = C:\boost\boost_1_65_1\stage\lib
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1159 ] _boost_TEST_VERSIONS = 1.65.1;1.65.0;1.65;1.64.0;...
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1258 ] location of version.hpp: C:/boost/boost_1_65_1/boost/version.hpp
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1282 ] version.hpp reveals boost 1.65.1;...
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1368 ] guessed _boost_COMPILER = -vc141;-vc140
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1378 ] _boost_MULTITHREADED = -mt
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1422 ] _boost_RELEASE_ABI_TAG = -
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1424 ] _boost_DEBUG_ABI_TAG = -gd
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1486 ] _boost_LIBRARY_SEARCH_DIRS_RELEASE = C:\boost\boost_1_65_1\stage\lib;C:\boost\boost_1_65_1/lib;...
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1636 ] Searching for FILESYSTEM_LIBRARY_RELEASE: boost_filesystem-vc141-mt-1_65_1;boost_filesystem-vc141-mt
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1687 ] Searching for FILESYSTEM_LIBRARY_DEBUG: boost_filesystem-vc141-mt-gd-1_65_1;boost_filesystem-vc141-mt-gd
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1636 ] Searching for SYSTEM_LIBRARY_RELEASE: boost_system-vc141-mt-1_65_1;boost_system-vc141-mt
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1687 ] Searching for SYSTEM_LIBRARY_DEBUG: boost_system-vc141-mt-gd-1_65_1;boost_system-vc141-mt-gd
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1762 ] Boost_FOUND = 1
1> -- Boost LIBRARIES:
1> CMake Error at C:/Program Files (x86)/.../FindBoost.cmake:1923 (message):
1> Unable to find the requested Boost libraries.
1>
1> Boost version: 1.65.1
1>
1> Boost include path: C:/boost/boost_1_65_1
1>
1> Could not find the following Boost libraries:
1>
1> boost_filesystem
1>
1> Some (but not all) of the required Boost libraries were found. You may
1> need to install these additional Boost libraries. Alternatively, set
1> BOOST_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT
1> to the location of Boost.
1> Call Stack (most recent call first):
1> CMakeLists.txt(17): (find_package)
1>
1>
1> -- Configuring incomplete, errors occurred!
1> See also "C:/Users/david/CMakeBuilds/94321a3b-9fa8-083f-a86f-e151c3abae79/build/x64-Release/CMakeFiles/CMakeOutput.log".
1> C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2017\PROFESSIONAL\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe -G "Ninja" -DCMAKE_INSTALL_PREFIX:PATH="C:\Users\david\CMakeBuilds\94321a3b-9fa8-083f-a86f-e151c3abae79\install\x64-Release" -DCMAKE_CXX_COMPILER="C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.13.26128/bin/HostX64/x64/cl.exe" -DCMAKE_C_COMPILER="C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.13.26128/bin/HostX64/x64/cl.exe" -DCMAKE_BUILD_TYPE="RelWithDebInfo" -DCMAKE_MAKE_PROGRAM="C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2017\PROFESSIONAL\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" "E:\computer\boost\cmake" returned with exit code: 1
CMake Error at C:/Program Files (x86)/.../FindBoost.cmake:1923 (message):
Unable to find the requested Boost libraries.
Boost version: 1.65.1
Boost include path: C:/boost/boost_1_65_1
Could not find the following Boost libraries:
boost_filesystem
Some (but not all) of the required Boost libraries were found. You may
need to install these additional Boost libraries. Alternatively, set
BOOST_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT
to the location of Boost.
Call Stack (most recent call first):
CMakeLists.txt:17 (find_package)
libboost_filesystem-vc141-mt-gd-1_65_1.lib is the static version of the filesystem library (the name starts with lib)
In CMake you are searching for the dynamic version:
set(Boost_USE_STATIC_LIBS OFF)
This cannot work. Now you have to options:
switch the OFF to ON
rebuild boost with the following addition:
b2 toolset=msvc-14.1 address-model=64 --build-type=complete
The command --build-type=complete build all supported variants of the libraries. Just to be on the safe side ;-)