Configuring czmq, zmq, and sodium with CMake - c++

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

Related

OpenCV & OpenCV contrib build Windows 11

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

MariaDB Connector/c++ throwing exception

I am trying to connect to my MariaDB instance using the MariaDB Connector/c++. Here is the code where I tried to use the already compiled version of the connector:
#include <iostream>
#include <mariadb/conncpp.hpp>
int main()
{
std::cout << "Hello World!\n";
try
{
// Instantiate Driver
sql::Driver* driver = sql::mariadb::get_driver_instance();
// Configure Connection
sql::SQLString url("jdbc:mariadb://X.X.X.X:3306/myMariaDB");
sql::Properties properties({
{"user", "root"},
{"password", "myPassword"},
{"useTls", "true"},
{"tlsCA", "myFile.pem"}
});
// Establish Connection
std::unique_ptr<sql::Connection> conn(driver->connect(url, properties));
std::cout << "I connected successfully!";
conn->close();
}
catch (sql::SQLException& e)
{
std::cerr << "Error Connecting to MariaDB Platform: "
<< e.what() << std::endl;
// Exit (Failed)
return 1;
}
return 0;
}
Running the code throws exception at the //Establish Connection line:
Exception thrown: read access violation.
other.theString._Mypair._Myval2 was 0xFFFFFFFFFFFFFFEF.
Searching the internet people suggested to recompile the connector source which I got from Github https://github.com/mariadb-corporation/mariadb-connector-cpp#readme
I tried to compile the source using VS 2019 and CMake. I have to say that this is my first encounter with CMake and I know very little about it. It seems that both are failing to build the cloned repo. below is the error I get form VS 2019 which is very similar to what I get from CMake. I also get an error in the "Error List" tab in VS 2019 : CMAke Error at libmariadb/cmake/version_info.cmake:15 (STRING):...:
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 (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe" -G "Ninja" -DCMAKE_BUILD_TYPE:STRING="Debug" -DCMAKE_INSTALL_PREFIX:PATH="C:\Users\RezaNoAdmin\Desktop\mariadb-connector-cpp\out\install\x64-Debug" -DCMAKE_C_COMPILER:FILEPATH="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe" -DCMAKE_CXX_COMPILER:FILEPATH="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe" -DCMAKE_MAKE_PROGRAM="C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" "C:\Users\RezaNoAdmin\Desktop\mariadb-connector-cpp" 2>&1"
1> Working directory: C:\Users\RezaNoAdmin\Desktop\mariadb-connector-cpp\out\build\x64-Debug
1> [CMake] -- The CXX compiler identification is MSVC 19.29.30133.0
1> [CMake] -- The C compiler identification is MSVC 19.29.30133.0
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 (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
1> [CMake] -- Detecting CXX compile features
1> [CMake] -- Detecting CXX compile features - done
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 (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
1> [CMake] -- Detecting C compile features
1> [CMake] -- Detecting C compile features - done
1> [CMake] -- CMAKE_CXX_FLAGS_DEBUG= /MTd /Zi /Ob0 /Od /RTC1
1> [CMake] -- CMAKE_C_FLAGS_DEBUG= /MTd /Zi /Ob0 /Od /RTC1
1> [CMake] -- CMAKE_CXX_FLAGS_RELEASE= /MT /O2 /Ob2 /DNDEBUG
1> [CMake] -- CMAKE_C_FLAGS_RELEASE= /MT /O2 /Ob2 /DNDEBUG
1> [CMake] -- CMAKE_CXX_FLAGS_RELWITHDEBINFO= /MT /Zi /O2 /Ob1 /DNDEBUG
1> [CMake] -- CMAKE_C_FLAGS_RELWITHDEBINFO= /MT /Zi /O2 /Ob1 /DNDEBUG
1> [CMake] -- CMAKE_CXX_FLAGS_MINSIZEREL= /MT /O1 /Ob1 /DNDEBUG
1> [CMake] -- CMAKE_C_FLAGS_MINSIZEREL= /MT /O1 /Ob1 /DNDEBUG
1> [CMake] -- MariaDB Connector ODBC: INSTALL_BINDIR=
1> [CMake] -- MariaDB Connector ODBC: INSTALL_LIBDIR=/mariadb
1> [CMake] -- MariaDB Connector ODBC: INSTALL_PCDIR=/pkgconfig
1> [CMake] -- MariaDB Connector ODBC: INSTALL_INCLUDEDIR=include/mariadb
1> [CMake] -- MariaDB Connector ODBC: INSTALL_DOCDIR=share/doc/mariadbcpp
1> [CMake] -- MariaDB Connector ODBC: INSTALL_LICENSEDIR=share/doc/mariadbcpp
1> [CMake] -- MariaDB Connector ODBC: INSTALL_PLUGINDIR=plugin
1> [CMake] -- Generate MSI package: ON
1> [CMake] -- Sign MSI package: OFF
1> [CMake] -- Setting deafault value for WITH_SSL for libmariadb build to ON
1> [CMake] -- Running C/C cmake scripts
1> [CMake] -- Found Git: C:/Windows/System32/git
1> [CMake] == Configuring MariaDB Connector/C
1> [CMake] CMake Warning (dev) at libmariadb/CMakeLists.txt:19 (PROJECT):
1> [CMake] Policy CMP0048 is not set: project() command manages VERSION variables.
1> [CMake] Run "cmake --help-policy CMP0048" for policy details. Use the cmake_policy
1> [CMake] command to set the policy and suppress this warning.
1> [CMake]
1> [CMake] The following variable(s) would be set to empty:
1> [CMake]
1> [CMake] PROJECT_VERSION
1> [CMake] PROJECT_VERSION_MAJOR
1> [CMake] PROJECT_VERSION_MINOR
1> [CMake] PROJECT_VERSION_PATCH
1> [CMake] This warning is for project developers. Use -Wno-dev to suppress it.
1> [CMake]
1> [CMake] -- Could NOT find CURL (missing: CURL_LIBRARY CURL_INCLUDE_DIR)
1> [CMake] -- MariaDB Connector C: INSTALL_BINDIR=bin
1> [CMake] -- MariaDB Connector C: INSTALL_LIBDIR=/mariadb
1> [CMake] -- MariaDB Connector C: INSTALL_PCDIR=/pkgconfig
1> [CMake] -- MariaDB Connector C: INSTALL_INCLUDEDIR=include/mariadb
1> [CMake] -- MariaDB Connector C: INSTALL_DOCSDIR=
1> [CMake] -- MariaDB Connector C: INSTALL_PLUGINDIR=plugin
1> [CMake] -- MariaDB Connector C: LIBMARIADB_STATIC_NAME mariadbclient
1> [CMake] -- Looking for include file alloca.h
1> [CMake] -- Looking for include file alloca.h - not found
1> [CMake] -- Looking for include file arpa/inet.h
1> [CMake] -- Looking for include file arpa/inet.h - not found
1> [CMake] -- Looking for include file dlfcn.h
1> [CMake] -- Looking for include file dlfcn.h - not found
1> [CMake] -- Looking for include file fcntl.h
1> [CMake] -- Looking for include file fcntl.h - found
1> [CMake] -- Looking for include file float.h
1> [CMake] -- Looking for include file float.h - found
1> [CMake] -- Looking for include file limits.h
1> [CMake] -- Looking for include file limits.h - found
1> [CMake] -- Looking for include file linux/limits.h
1> [CMake] -- Looking for include file linux/limits.h - not found
1> [CMake] -- Looking for include file pwd.h
1> [CMake] -- Looking for include file pwd.h - not found
1> [CMake] -- Looking for include file sched.h
1> [CMake] -- Looking for include file sched.h - not found
1> [CMake] -- Looking for include file select.h
1> [CMake] -- Looking for include file select.h - not found
1> [CMake] -- Looking for include file signal.h
1> [CMake] -- Looking for include file signal.h - found
1> [CMake] -- Looking for include file stddef.h
1> [CMake] -- Looking for include file stddef.h - found
1> [CMake] -- Looking for include file stdint.h
1> [CMake] -- Looking for include file stdint.h - found
1> [CMake] -- Looking for include file stdlib.h
1> [CMake] -- Looking for include file stdlib.h - found
1> [CMake] -- Looking for include file string.h
1> [CMake] -- Looking for include file string.h - found
1> [CMake] -- Looking for include file strings.h
1> [CMake] -- Looking for include file strings.h - not found
1> [CMake] -- Looking for include file sys/ioctl.h
1> [CMake] -- Looking for include file sys/ioctl.h - not found
1> [CMake] -- Looking for include file sys/select.h
1> [CMake] -- Looking for include file sys/select.h - not found
1> [CMake] -- Looking for include file sys/socket.h
1> [CMake] -- Looking for include file sys/socket.h - not found
1> [CMake] -- Looking for include file sys/types.h
1> [CMake] -- Looking for include file sys/types.h - found
1> [CMake] -- Looking for include file sys/stat.h
1> [CMake] -- Looking for include file sys/stat.h - found
1> [CMake] -- Looking for include file sys/un.h
1> [CMake] -- Looking for include file sys/un.h - not found
1> [CMake] -- Looking for include file unistd.h
1> [CMake] -- Looking for include file unistd.h - not found
1> [CMake] -- Looking for include file utime.h
1> [CMake] -- Looking for include file utime.h - not found
1> [CMake] -- Looking for include file ucontext.h
1> [CMake] -- Looking for include file ucontext.h - not found
1> [CMake] -- Looking for alloca
1> [CMake] -- Looking for alloca - not found
1> [CMake] -- Looking for dlerror
1> [CMake] -- Looking for dlerror - not found
1> [CMake] -- Looking for dlopen
1> [CMake] -- Looking for dlopen - not found
1> [CMake] -- Looking for fcntl
1> [CMake] -- Looking for fcntl - not found
1> [CMake] -- Looking for memcpy
1> [CMake] -- Looking for memcpy - found
1> [CMake] -- Looking for nl_langinfo
1> [CMake] -- Looking for nl_langinfo - not found
1> [CMake] -- Looking for setlocale
1> [CMake] -- Looking for setlocale - found
1> [CMake] -- Looking for poll
1> [CMake] -- Looking for poll - not found
1> [CMake] -- Looking for getpwuid
1> [CMake] -- Looking for getpwuid - not found
1> [CMake] -- Looking for cuserid
1> [CMake] -- Looking for cuserid - not found
1> [CMake] -- Check size of char *
1> [CMake] -- Check size of char * - done
1> [CMake] -- Check size of int
1> [CMake] -- Check size of int - done
1> [CMake] -- Check size of long
1> [CMake] -- Check size of long - done
1> [CMake] -- Check size of long long
1> [CMake] -- Check size of long long - done
1> [CMake] -- Check size of size_t
1> [CMake] -- Check size of size_t - done
1> [CMake] -- Check size of uchar
1> [CMake] -- Check size of uchar - failed
1> [CMake] -- Check size of uint
1> [CMake] -- Check size of uint - failed
1> [CMake] -- Check size of ulong
1> [CMake] -- Check size of ulong - failed
1> [CMake] -- Check size of int8
1> [CMake] -- Check size of int8 - failed
1> [CMake] -- Check size of uint8
1> [CMake] -- Check size of uint8 - failed
1> [CMake] -- Check size of int16
1> [CMake] -- Check size of int16 - failed
1> [CMake] -- Check size of uint16
1> [CMake] -- Check size of uint16 - failed
1> [CMake] -- Check size of int32
1> [CMake] -- Check size of int32 - failed
1> [CMake] -- Check size of uint32
1> [CMake] -- Check size of uint32 - failed
1> [CMake] -- Check size of int64
1> [CMake] -- Check size of int64 - failed
1> [CMake] -- Check size of uint64
1> [CMake] -- Check size of uint64 - failed
1> [CMake] -- Check size of socklen_t
1> [CMake] -- Check size of socklen_t - failed
1> [CMake] -- TLS library/version: Schannel 10.0.19042
1> [CMake] -- SYSTEM_LIBS ws2_32;advapi32;kernel32;shlwapi;crypt32;secur32
1> [CMake] CMake Error at libmariadb/cmake/version_info.cmake:15 (STRING):
1> [CMake] STRING sub-command REPLACE requires at least four arguments.
1> [CMake] Call Stack (most recent call first):
1> [CMake] libmariadb/cmake/version_info.cmake:33 (GET_FILE_VERSION)
1> [CMake] libmariadb/libmariadb/CMakeLists.txt:390 (SET_VERSION_INFO)
1> [CMake] -- SYSTEM processor: AMD64
1> [CMake] -- MariaDB Connector/c configuration:
1> [CMake] -- Static PLUGINS mysql_native_password;mysql_old_password;pvio_socket
1> [CMake] -- Dynamic PLUGINS dialog;client_ed25519;caching_sha2_password;sha256_password;auth_gssapi_client;mysql_clear_password;pvio_npipe;pvio_shmem
1> [CMake] -- CPack generation: ZIP
1> [CMake] -- SSL support: SCHANNEL Libs: secur32
1> [CMake] -- Zlib support: yes (using bundled zlib)
1> [CMake] -- Installation layout: DEFAULT
1> [CMake] -- Include files will be installed in include/mariadb
1> [CMake] -- Libraries will be installed in /mariadb
1> [CMake] -- Binaries will be installed in bin
1> [CMake] -- Documentation included from
1> [CMake] -- Required:
1> [CMake] -- Configuring to install libmariadb to /mariadb
1> [CMake] -- Configuring to install mysql_clear_password to plugin
1> [CMake] -- Configuring to install dialog to plugin
1> [CMake] -- Configuring to install client_ed25519 to plugin
1> [CMake] -- Configuring to install sha256_password to plugin
1> [CMake] -- Configuring to install caching_sha2_password to plugin
1> [CMake] -- Linking Connector/C library statically(mariadbclient)
1> [CMake] -- WiX directory: /bin/
1> [CMake] -- MSI package name mariadb-connector-cpp-1.0.2-win64.msi
1> [CMake] -- Configuring tests framework lib
1> [CMake] -- Configuring C/J junit tests port
1> [CMake] -- Configuring unit tests
1> [CMake] -- Configuring unit tests - examples
1> [CMake] -- Configuring unit tests - connection
1> [CMake] -- Configuring unit tests - databasemetadata
1> [CMake] -- Configuring unit tests - resultsetmetadata
1> [CMake] -- Configuring unit tests - resultset
1> [CMake] -- Configuring unit tests - savepoint
1> [CMake] -- Configuring unit tests - preparedstatement
1> [CMake] -- Configuring unit tests - parametermetadata
1> [CMake] -- Configuring unit tests - statement
1> [CMake] -- Configuring performance test - statement
1> [CMake] -- Configuring bugs test cases - unsorted
1> [CMake] -- Configuring test cases
1> [CMake] -- Package Name: mariadb-connector-cpp-1.0.2-windows-AMD64
1> [CMake] -- License File: C:/Users/RezaNoAdmin/Desktop/mariadb-connector-cpp/COPYING
1> [CMake] -- ReadMe File: C:/Users/RezaNoAdmin/Desktop/mariadb-connector-cpp/README
1> [CMake] -- Source Package Filename: mariadb-connector-cpp-1.0.2-src.ZIP
1> [CMake] -- Configuring incomplete, errors occurred!
1> [CMake] See also "C:/Users/RezaNoAdmin/Desktop/mariadb-connector-cpp/out/build/x64-Debug/CMakeFiles/CMakeOutput.log".
1> [CMake] See also "C:/Users/RezaNoAdmin/Desktop/mariadb-connector-cpp/out/build/x64-Debug/CMakeFiles/CMakeError.log".
1> 'C:\WINDOWS\system32\cmd.exe' '/c "%SYSTEMROOT%\System32\chcp.com 65001 >NUL && "C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe" -G "Ninja" -DCMAKE_BUILD_TYPE:STRING="Debug" -DCMAKE_INSTALL_PREFIX:PATH="C:\Users\RezaNoAdmin\Desktop\mariadb-connector-cpp\out\install\x64-Debug" -DCMAKE_C_COMPILER:FILEPATH="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe" -DCMAKE_CXX_COMPILER:FILEPATH="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe" -DCMAKE_MAKE_PROGRAM="C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" "C:\Users\RezaNoAdmin\Desktop\mariadb-connector-cpp" 2>&1"' execution failed with error: ''C:\WINDOWS\system32\cmd.exe' '/c "%SYSTEMROOT%\System32\chcp.com 65001 >NUL && "C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe" -G "Ninja" -DCMAKE_BUILD_TYPE:STRING="Debug" -DCMAKE_INSTALL_PREFIX:PATH="C:\Users\RezaNoAdmin\Desktop\mariadb-connector-cpp\out\install\x64-Debug" -DCMAKE_C_COMPILER:FILEPATH="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe" -DCMAKE_CXX_COMPILER:FILEPATH="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe" -DCMAKE_MAKE_PROGRAM="C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" "C:\Users\RezaNoAdmin\Desktop\mariadb-connector-cpp" 2>&1"' returned with exit code: 1'.
I have ran out of ideas on how to resolve this. Any help is much appreciated.
In the mariadb c++ connector site(https://github.com/mariadb-corporation/mariadb-connector-cpp)
git clone
git clone https://github.com/MariaDB-Corporation/mariadb-connector-cpp.git
build with debug mode(default is Release with Debug info)
cmake -DCMAKE_BUILD_TYPE=DEBUG -DCONC_WITH_UNIT_TESTS=Off -DCONC_WITH_MSI=OFF -DWITH_SSL=SCHANNEL .
cmake --build . --config DEBUG
replace previous library with debug..

Can't generate CMake files with Visual Studio

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")

CMake project compilation error on VisualStudio using external SDK toolchain file

I am using VisualStudio CMake project on Windows machine.
I am using an external SDK in order to cross compile my C++ program for Linux arm architecture.
I added the SDK toolchain to cmakeToolchain path which is :
/opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/share/cmake/OEToolchainConfig.cmake
and this is my CMakeLists.txt file :
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED OFF)
set(Boost_USE_STATIC_RUNTIME OFF)
#list(APPEND CMAKE_PREFIX_PATH /home/ubuntu/linux4sam/poky/build-microchip/tmp/sysroots-components/cortexa5hf-neon/boost/usr/include/boost)
list(APPEND CMAKE_PREFIX_PATH /opt/poky-atmel/2.5.3/sysroots/cortexa5hf-neon-poky-linux-gnueabi/usr/include)
Set(Boost_NO_BOOST_CMAKE ON)
#set(BOOST_ROOT "/home/ubuntu/linux4sam/poky/build-microchip/tmp/sysroots-components/cortexa5hf-neon/boost")
message(STATUS "CMAKE_TOOLCHAIN_FILE='${CMAKE_TOOLCHAIN_FILE}'")
set(CROSS_COMPILER_DIR /opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr)
set(CMAKE_C_COMPILER ${CROSS_COMPILER_DIR}/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc)
set(CMAKE_CXX_COMPILER ${CROSS_COMPILER_DIR}/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc)
#set(CMAKE_SYSTEM_NAME Linux)
message(STATUS "CMAKE_C_COMPILER='${CMAKE_C_COMPILER}'")
message(STATUS "CMAKE_CXX_COMPILER='${CMAKE_CXX_COMPILER}'")
find_package(Boost 1.66.0)
if(Boost_FOUND)
message (STATUS "success!")
add_executable (CMakeProject4 "CMakeProject4.cpp" "CMakeProject4.h")
include_directories(${Boost_INCLUDE_DIRS})
target_link_libraries(CMakeProject4 ${Boost_LIBRARIES})
endif()
As you can see I am setting my SDK compilers bin paths to CMAKE_C_COMPILER and CMAKE_CXX_COMPILER variables.
When I Debug, I find that :
1> Copying files to the remote machine.
1> Starting copying files to remote machine.
1> [rsync] rsync -t --delete --delete-excluded -v -r --exclude=.vs --exclude=.git --exclude=out "." rsync://ubuntu#localhost:56934/-home-ubuntu-CMake-RemoteCML
1> [rsync] sending incremental file list
1> [rsync]
1> [rsync] sent 229 bytes received 13 bytes 161.33 bytes/sec
1> [rsync] total size is 4,429 speedup is 18.30
1> Finished copying files (elapsed time 00h:00m:04s:043ms).
1> CMake generation started for configuration: 'Linux-Release'.
1> Found cmake executable at /home/ubuntu/.vs/cmake/bin/cmake.
1> /home/ubuntu/.vs/cmake/bin/cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE="RelWithDebInfo" -DBoost_INCLUDE_DIRS:PATH="/opt/poky-atmel/2.5.3/sysroots/cortexa5hf-neon-poky-linux-gnueabi/usr/include" -DBoost_LIBRARIES:PATH="/opt/poky-atmel/2.5.3/sysroots/cortexa5hf-neon-poky-linux-gnueabi/usr/lib" -DBoost_INCLUDE_DIR:PATH="/opt/poky-atmel/2.5.3/sysroots/cortexa5hf-neon-poky-linux-gnueabi/usr/include" -DBoost_DEBUG=ON -DCMAKE_CXX_COMPILER=/opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc -DCMAKE_TOOLCHAIN_FILE="/opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/share/cmake/OEToolchainConfig.cmake" -DCMAKE_INSTALL_PREFIX=/home/ubuntu/CMake/RemoteIL "/home/ubuntu/CMake/RemoteCML/CMakeLists.txt";
1> [CMake] -- The C compiler identification is GNU 7.4.0
1> [CMake] -- The CXX compiler identification is GNU 7.3.0
1> [CMake] -- Check for working C compiler: /usr/bin/cc
1> [CMake] -- Check for working C compiler: /usr/bin/cc -- 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: /opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc
1> [CMake] -- Check for working CXX compiler: /opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc -- broken
1> [CMake] CMake Error at /home/ubuntu/.vs/cmake/share/cmake-3.15/Modules/CMakeTestCXXCompiler.cmake:53 (message):
1> [CMake] The C++ compiler
1> [CMake]
1> [CMake] "/opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc"
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: /home/ubuntu/CMake/RemoteBR/CMakeFiles/CMakeTmp
1> [CMake]
1> [CMake] Run Build Command(s):/usr/bin/make cmTC_2cb5a/fast && /usr/bin/make -f CMakeFiles/cmTC_2cb5a.dir/build.make CMakeFiles/cmTC_2cb5a.dir/build
1> [CMake] make[1]: Entering directory '/home/ubuntu/CMake/RemoteBR/CMakeFiles/CMakeTmp'
1> [CMake] Building CXX object CMakeFiles/cmTC_2cb5a.dir/testCXXCompiler.cxx.o
1> [CMake] /opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc -o CMakeFiles/cmTC_2cb5a.dir/testCXXCompiler.cxx.o -c /home/ubuntu/CMake/RemoteBR/CMakeFiles/CMakeTmp/testCXXCompiler.cxx
1> [CMake] Linking CXX executable cmTC_2cb5a
1> [CMake] /home/ubuntu/.vs/cmake/bin/cmake -E cmake_link_script CMakeFiles/cmTC_2cb5a.dir/link.txt --verbose=1
1> [CMake] /opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc CMakeFiles/cmTC_2cb5a.dir/testCXXCompiler.cxx.o -o cmTC_2cb5a
1> [CMake] /opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/7.3.0/real-ld: cannot find crt1.o: No such file or directory
1> [CMake] /opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/7.3.0/real-ld: cannot find crti.o: No such file or directory
1> [CMake] /opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/7.3.0/real-ld: cannot find crtbegin.o: No such file or directory
1> [CMake] /opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/7.3.0/real-ld: cannot find -lgcc
1> [CMake] /opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/7.3.0/real-ld: cannot find -lgcc_s
1> [CMake] /opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/7.3.0/real-ld: cannot find -lc
1> [CMake] /opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/7.3.0/real-ld: cannot find -lgcc
1> [CMake] /opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/7.3.0/real-ld: cannot find -lgcc_s
1> [CMake] /opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/7.3.0/real-ld: cannot find crtend.o: No such file or directory
1> [CMake] /opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/7.3.0/real-ld: cannot find crtn.o: No such file or directory
1> [CMake] collect2: error: ld returned 1 exit status
1> [CMake] CMakeFiles/cmTC_2cb5a.dir/build.make:86: recipe for target 'cmTC_2cb5a' failed
1> [CMake] make[1]: *** [cmTC_2cb5a] Error 1
1> [CMake] make[1]: Leaving directory '/home/ubuntu/CMake/RemoteBR/CMakeFiles/CMakeTmp'
1> [CMake] Makefile:121: recipe for target 'cmTC_2cb5a/fast' failed
1> [CMake] make: *** [cmTC_2cb5a/fast] Error 2
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:6 (project)
1> [CMake] -- Configuring incomplete, errors occurred!
1> [CMake] See also "/home/ubuntu/CMake/RemoteBR/CMakeFiles/CMakeOutput.log".
1> [CMake] See also "/home/ubuntu/CMake/RemoteBR/CMakeFiles/CMakeError.log".
1> cd "/home/ubuntu/CMake/RemoteBR";/home/ubuntu/.vs/cmake/bin/cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE="RelWithDebInfo" -DBoost_INCLUDE_DIRS:PATH="/opt/poky-atmel/2.5.3/sysroots/cortexa5hf-neon-poky-linux-gnueabi/usr/include" -DBoost_LIBRARIES:PATH="/opt/poky-atmel/2.5.3/sysroots/cortexa5hf-neon-poky-linux-gnueabi/usr/lib" -DBoost_INCLUDE_DIR:PATH="/opt/poky-atmel/2.5.3/sysroots/cortexa5hf-neon-poky-linux-gnueabi/usr/include" -DBoost_DEBUG=ON -DCMAKE_CXX_COMPILER=/opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc -DCMAKE_TOOLCHAIN_FILE="/opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/share/cmake/OEToolchainConfig.cmake" -DCMAKE_INSTALL_PREFIX=/home/ubuntu/CMake/RemoteIL "/home/ubuntu/CMake/RemoteCML" 2>&1; returned with exit code: 1
I can see here that CMake can identify the SDK toolchain compiler which I want to use which is GNU 7.3.0 but it's broken!
When I open CMakeCache.txt , I find this :
//No help, variable specified on the command line.
CMAKE_CXX_COMPILER:UNINITIALIZED=/opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc
//A wrapper around 'ar' adding the appropriate '--plugin' option
// for the GCC compiler
CMAKE_CXX_COMPILER_AR:FILEPATH=/usr/bin/gcc-ar-7
//A wrapper around 'ranlib' adding the appropriate '--plugin' option
// for the GCC compiler
CMAKE_CXX_COMPILER_RANLIB:FILEPATH=/usr/bin/gcc-ranlib-7
CMAKE_CXX_FLAGS:STRING=
//Flags used by the CXX compiler during DEBUG builds.
CMAKE_CXX_FLAGS_DEBUG:STRING=-g
//Flags used by the CXX compiler during MINSIZEREL builds.
CMAKE_CXX_FLAGS_MINSIZEREL:STRING=-Os -DNDEBUG
//Flags used by the CXX compiler during RELEASE builds.
CMAKE_CXX_FLAGS_RELEASE:STRING=-O3 -DNDEBUG
//Flags used by the CXX compiler during RELWITHDEBINFO builds.
CMAKE_CXX_FLAGS_RELWITHDEBINFO:STRING=-O2 -g -DNDEBUG
//No help, variable specified on the command line.
CMAKE_TOOLCHAIN_FILE:UNINITIALIZED=/opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/share/cmake/OEToolchainConfig.cmake
This is my C++ .cpp file program :
#include "CMakeProject4.h"
#include <boost/lambda/lambda.hpp>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
int main()
{
typedef std::istream_iterator<int> in;
std::cout << "Type in any number: ";
std::for_each(
in(std::cin), in(), std::cout
<< (boost::lambda::_1 * 10)
<< "\nType in another number: ");
}
But when I try to run CMake in order to compile my program using :
cmake -DBoost_DEBUG=ON -DCMAKE_CXX_COMPILER=/opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc
I have this error :
Error Compilation
Any help please ?
When you use a toolchain file, you shouldn't set the compiler yourself. You should let it to the toolchain file, as it know how to cross compile. Things like CMAKE_SYSTEM_NAME and CMAKE_SYSTEM_PROCESSOR should be left to the toolchain file.
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED OFF)
set(Boost_USE_STATIC_RUNTIME OFF)
set(Boost_NO_BOOST_CMAKE ON)
# I think the prefix should point to usr directly, not the include directory
list(APPEND CMAKE_PREFIX_PATH /opt/poky-atmel/2.5.3/sysroots/cortexa5hf-neon-poky-linux-gnueabi/usr)
message(STATUS "CMAKE_TOOLCHAIN_FILE='${CMAKE_TOOLCHAIN_FILE}'")
message(STATUS "CMAKE_C_COMPILER='${CMAKE_C_COMPILER}'")
message(STATUS "CMAKE_CXX_COMPILER='${CMAKE_CXX_COMPILER}'")
project(whatever CXX)
# Better to fail fast when there's a package missing
find_package(Boost 1.66.0 REQUIRED)
add_executable (CMakeProject4 CMakeProject4.cpp CMakeProject4.h)
target_link_libraries(CMakeProject4 PRIVATE Boost::headers)
And your CMake arguments should look like this:
cmake -DCMAKE_TOOLCHAIN_FILE=/opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/share/cmake/OEToolchainConfig.cmake

Using OpenMP with Clang and CMake in Visual Studio

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.