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.
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 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
I'm currently getting this error while trying to configure a project on CMAKE using Visual Studio 15 2017 Win64:
The C compiler identification is MSVC 19.11.25547.0
The CXX compiler identification is MSVC 19.11.25547.0
Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.11.25503/bin/Hostx86/x64/cl.exe
Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.11.25503/bin/Hostx86/x64/cl.exe -- works
Detecting C compiler ABI info
Detecting C compiler ABI info - done
Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.11.25503/bin/Hostx86/x64/cl.exe
Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.11.25503/bin/Hostx86/x64/cl.exe -- works
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Detecting CXX compile features
Detecting CXX compile features - done
Found OpenGL: opengl32
Looking for pthread.h
Looking for pthread.h - not found
Found Threads: TRUE
Using Win32 for window creation
Using WGL for context creation
Lib glbinding
Performing Test COMPILER_HAS_DEPRECATED_ATTR
Performing Test COMPILER_HAS_DEPRECATED_ATTR - Failed
Performing Test COMPILER_HAS_DEPRECATED
Performing Test COMPILER_HAS_DEPRECATED - Success
Configuring done
I've used this compiler to generate another project and it still works.
Here is the code relevant to the new CMakeLists.txt:
project(ms3d_td3)
cmake_minimum_required(VERSION 3.2.0)
add_subdirectory(ext/glfw)
add_subdirectory(ext/glbinding)
include_directories(ext/glfw/include)
include_directories(ext/glbinding/include)
include_directories(ext/eigen3)
if(APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif()
set(SRC_FILES
src/main.cpp
src/viewer.cpp
src/viewer.h
src/shader.cpp
src/shader.h
src/opengl.h)
add_definitions(-DDATA_DIR="${PROJECT_SOURCE_DIR}/data")
add_executable(ms3d_td3 ${SRC_FILES})
target_link_libraries(ms3d_td3 glfw ${GLFW_LIBRARIES} glbinding)
Under Visual Studio 2017 I get a CMAKE_C_COMPILER not set after EnableLanguage. I tried to set it manually to the VisualStudio 2017 compiler but no success. Any ideas?
Another person had a similar problem and solved it by upgrading Visual Studio a while ago so I'm guessing this is coming from somewhere else... :
Compiler failing on C++11 instructions in a Visual Studio project configured with cmake
Thanks!
To require compiler support for the [[decprecated]] attribute, use target_compile_features and specify the cxx_attribute_deprecated feature. For example:
add_executable(foo foo.cpp)
target_compile_features(foo PRIVATE cxx_attribute_deprecated)
If you need to conditionally test for this so that you can configure a header file, use check_cxx_source_compiles.
Hej, I have a problem running my project with Cmake.
But I am getting an error.
"Could NOT find Boost"
I have the boost folder in
"C:\Program Fileenter code heres\PCL 1.6.0\3rdParty\Boost"
images: http://imgur.com/a/YgtQR
At first I got a error popup:
"error in configuration process, projekt files may be invalid"
Than I get this error.
The C compiler identification is MSVC 19.0.24215.1
The CXX compiler identification is MSVC 19.0.24215.1
Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe
Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe -- works
Detecting C compiler ABI info
Detecting C compiler ABI info - done
Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe
Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe -- works
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Detecting CXX compile features
Detecting CXX compile features - done
Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE)
Found eigen: C:/Program Files/PCL 1.6.0/3rdParty/Eigen/include
Looking for pthread.h
Looking for pthread.h - not found
Found Threads: TRUE
Could NOT find Boost
CMake Error at
C:/Program Files/PCL 1.6.0/cmake/PCLConfig.cmake:39 (message):
common is required but boost was not found
Call Stack (most recent call first):
C:/Program Files/PCL 1.6.0/cmake/PCLConfig.cmake:354 (pcl_report_not_found)
C:/Program Files/PCL 1.6.0/cmake/PCLConfig.cmake:500 (find_external_library)
CMakeLists.txt:5 (find_package)
Configuring incomplete, errors occurred!
See also "//mac/Home/Documents/Visual Studio 2015/Projects/openni_range_image_visualization/build/CMakeFiles/CMakeOutput.log".
See also "//mac/Home/Documents/Visual Studio 2015/Projects/openni_range_image_visualization/build/CMakeFiles/CMakeError.log".
my CMakeLists contains:
cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
project(openni_range_image_visualization)
find_package(PCL 1.3 REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
add_executable (openni_range_image_visualization openni_range_image_visualization.cpp)
target_link_libraries (openni_range_image_visualization ${PCL_LIBRARIES})
This was asked a few years back, but for anybody that is still running into this problem-- the default download instructions on the PCL website help install PCL 1.6.0, which is an old version of PCL that has this little "bug" with regards to boost.
Instead, head over to their Github page and download the latest release here:
https://github.com/PointCloudLibrary/pcl/releases
for this bug has been fixed in the later releases.