I've been struggling to understand why CMake does not compile my program anymore. I made a container for cross-compile a C++ program for Windows. The environment:
Fedora 31
cmake 3.17.4
x86_64-w64-mingw32-g++ 9.2.1
boost 1.69
The following code is my current cmake toolchain file for mingw:
set(CMAKE_SYSTEM_NAME Windows)
set(TOOLCHAIN_PFX x86_64-w64-mingw32)
set(Boost_ARCHITECTURE -x64)
set(Boost_DEBUG ON)
set(Boost_INCLUDE_DIR /usr/${TOOLCHAIN_PFX}/sys-root/mingw/include)
set(Boost_LIBRARY_DIR /usr/${TOOLCHAIN_PFX}/sys-root/mingw/lib)
set(Boost_USE_STATIC_LIBS ON)
find_package(Boost 1.69 REQUIRED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I/usr/local/include -L/usr/local/lib")
set(CMAKE_C_COMPILER ${TOOLCHAIN_PFX}-gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PFX}-g++)
set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PFX})
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
The building process interrupts when linking the executable. It produces:
/usr/lib/gcc/x86_64-w64-mingw32/9.2.1/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lboost_thread-mt
/usr/lib/gcc/x86_64-w64-mingw32/9.2.1/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lboost_log-mt
/usr/lib/gcc/x86_64-w64-mingw32/9.2.1/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lboost_system
What shocks me the most is that it used to build (no changes have been made to the environment) and boost is installed from RPM. Funny things is that if I omit -lboost_thread-mt, off course, it complains.
You are overwriting many variables that should be correctly set by find_package() such as Boost_LIBRARY_DIR.
Also, you don't specify any components with find_package, as would be the standard way, unless you just want to use the header-only part of boost.
Thus, you are using find_package boost in unsupported/unspecified ways which might have worked in the past, by chance, but broke later.
What definitely works on Fedora 36 is the following:
cmake_minimum_required(VERSION 3.0...3.22.1)
project(some_project CXX)
# work-around: FindBoost: Boost_ARCHITECTURE not detected on MinGW
# https://gitlab.kitware.com/cmake/cmake/-/issues/20587
if(MINGW)
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
set(Boost_ARCHITECTURE "-x64")
else()
set(Boost_ARCHITECTURE "-x32")
endif()
endif()
# works with/without
set(Boost_USE_STATIC_LIBS ON)
# set(Boost_DEBUG ON)
set(Boost_USE_STATIC_LIBS ON)
find_package(Boost 1.54
REQUIRED COMPONENTS
system
filesystem) # just an example, add what you need
add_executable(somebinary main.cc sometranslationunit.cc)
target_link_libraries(somebinary ${Boost_LIBRARIES})
Build with:
mkdir build-cross
cd build-cross
mingw64-cmake -DCMAKE_BUILD_TYPE=Debug .. # or whatever build type
mingw64-make somebinary
Related
I am currently trying to compile a project on Mac using cmake, but running into trouble. I have already looked at this article [1], but am still running into some trouble. My CMakeLists.txt looks as follows.
project(tpch_framework)
# enable c++11
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_BUILD_TYPE "Release")
set(CMAKE_C_COMPILER "/usr/local/Cellar/llvm/10.0.0_3/bin/clang")
set(CMAKE_CXX_COMPILER "/usr/local/Cellar/llvm/10.0.0_3/bin/clang++")
set(OPENMP_LIBRARIES "/usr/local/Cellar/llvm/10.0.0_3/lib")
set(OPENMP_INCLUDES "/usr/local/Cellar/llvm/10.0.0_3/include")
OPTION (USE_OpenMP "Use OpenMP to enamble <omp.h>" ON)
# Find OpenMP
if(APPLE AND USE_OpenMP)
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
set(OpenMP_C_FLAGS "-Xpreprocessor -fopenmp")
set(OpenMP_C_LIB_NAMES "omp")
set(OpenMP_omp_LIBRARY omp)
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(OpenMP_CXX_FLAGS "-Xpreprocessor -fopenmp")
set(OpenMP_CXX_LIB_NAMES "omp")
set(OpenMP_omp_LIBRARY omp)
endif()
endif()
if(USE_OpenMP)
find_package(OpenMP REQUIRED)
endif(USE_OpenMP)
if (OPENMP_FOUND)
include_directories("${OPENMP_INCLUDES}")
link_directories("${OPENMP_LIBRARIES}")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS} -libomp")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS} -libomp")
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
endif(OPENMP_FOUND)
# Configure required Boost libraries
set(BOOST_ROOT "" CACHE PATH "Boost build root (useful on Windows)")
option(Boost_USE_STATIC_LIBS
"Search for static boost libs" OFF)
option(Boost_USE_MULTITHREADED
"Search for multithreaded boost libs" ON)
option(Boost_USE_STATIC_RUNTIME
"Search for boost libs linked against static C++ runtime" OFF)
find_package(Boost 1.47.0 REQUIRED filesystem system)
# ensure that dependant libraries not explicitly specified here
# are found by the linker:
link_directories(${Boost_LIBRARY_DIRS})
include_directories(${Boost_INCLUDE_DIRS})
set(LIBS ${LIBS} ${Boost_LIBRARIES})
#Bring the headers into the project
include_directories(include)
FILE(GLOB_RECURSE INC_ALL "include/*.hpp")
#However, the file(GLOB...) allows for wildcard additions:
file(GLOB SOURCES "src/*.cpp")
add_library(tpch_framework ${SOURCES})
add_executable(framework main.cpp ${INC_ALL})
target_link_libraries(framework tpch_framework)
#target_link_libraries(framework stdc++fs)
target_link_libraries(framework ${LIBS})
When I execute this, I get the following output.
-- The C compiler identification is AppleClang 11.0.0.11000033
-- The CXX compiler identification is AppleClang 11.0.0.11000033
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc - works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ - works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found OpenMP_C: -Xpreprocessor -fopenmp
-- Found OpenMP_CXX: -Xpreprocessor -fopenmp
-- Found OpenMP: TRUE
-- Found Boost: /usr/local/lib/cmake/Boost-1.72.0/BoostConfig.cmake (found suitable version "1.72.0", minimum required is "1.47.0") found components: filesystem system
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/...
However, when I then use make, I get the following error.
/Users/myname/Desktop/Uni/MHD/tpch_framework_challenge_mhd_2020/src/task4.cpp:48:5: error: use of undeclared identifier 'omp_set_num_threads'
omp_set_num_threads(4);
Which I am guessing comes, as I get this warning: clang-10: warning: -libomp: 'linker' input unused [-Wunused-command-line-argument].
Does anybody have any ideas? I have been stuck with this for way too long and would appreciate any tips.
Kind regards,
Moritz
If you can use a recent version of CMake, this build should work.
# NOTE: Every top-level CMakeLists.txt must start with these two lines
cmake_minimum_required(VERSION 3.16)
project(tpch_framework)
## Enable C++14
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
## Find dependencies
# OpenMP
find_package(OpenMP REQUIRED)
# Boost
set(BOOST_ROOT "" CACHE PATH "Boost build root (useful on Windows)")
option(Boost_USE_STATIC_LIBS
"Search for static boost libs" OFF)
option(Boost_USE_MULTITHREADED
"Search for multithreaded boost libs" ON)
option(Boost_USE_STATIC_RUNTIME
"Search for boost libs linked against static C++ runtime" OFF)
find_package(Boost 1.47.0 REQUIRED COMPONENTS filesystem system)
## Add main project targets
# NOTE: This is completely wrong and will break incremental builds after
# doing a "git pull" or similar. You should never glob for source
# files, but instead list them explicitly.
file(GLOB SOURCES "src/*.cpp")
add_library(tpch_framework ${SOURCES})
target_include_directories(tpch_framework PUBLIC BUILD_INTERFACE:include)
target_link_libraries(tpch_framework
PUBLIC
OpenMP::OpenMP_CXX
Boost::boost
Boost::filesystem
Boost::system)
add_executable(framework main.cpp)
target_link_libraries(framework PRIVATE tpch_framework)
There is so much bad CMake advice here on SO and in tutorials, it's a real shame.
I'm attempting to add OpenMP to a project that is building with CMake. I'm having no problem building it on Linux with the standard CMake/OpenMP addition:
find_package(OpenMP)
if (OPENMP_FOUND)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}
${OpenMP_EXE_LINKER_FLAGS}")
endif()
Unfortunately this doesn't seem to work on macOS targets. When cmake is called, the following error is given:
-- Could NOT find OpenMP_C (missing: OpenMP_C_FLAGS)
-- Could NOT find OpenMP_CXX (missing: OpenMP_CXX_FLAGS)
-- Could NOT find OpenMP (missing: OpenMP_C_FOUND OpenMP_CXX_FOUND)
I'm using macOS High Sierra (10.13.3) along with CMake 3.11. I've installed OpenMP 5.01 via brew, 'brew install libomp'. I've found some previous posts commenting on issues regarding these three but they all seem to deal with a previous way of installing OpenMP on macOS, "brew install clang-omp".
I'm thinking this might have something to do with CMake not support this OpenMP install as I'm able to use OpenMP no problem with standard makefiles. Any information provided would be much appreciated.
I've been able to answer my own question (apologies for not figuring this out beforehand, hopefully this can help others with the same issue).
It seems that a patch has been submitted to CMake to allow it to properly create buildsystems with the new OpenMP install: https://gitlab.kitware.com/cmake/cmake/merge_requests/1812
For others seeing this in the future, update to CMake 3.12 if it has been released at the time of reading.
I had the same problem and it took one complete day to find the solution. I am using Mac-Sierra 10.13.4. I want to use Opencv3 (I think the same problem also appears for opencv2) and openMP. I was actually using Clion as the IDE (CLion uses cmake to configure the project unlike other IDE), so I have to write the CMakeLists.txt file.
There was a conflict of using gcc as the compiler for openCV and openMP. If you use gcc as the compiler then it gives error for opencv as :
imwrite() on OS X error: Undefined symbols
You need to specifically use llvm compiler on OS X to resolve this issue. Following, I am giving the correct code for using OpenCV and OpenMP on Mac-Sierra:
cmake_minimum_required(VERSION 3.10)
project(MyOpenCVTest)
set(CMAKE_CXX_STANDARD 11)
add_executable(MyOpenCVTest main.cpp)
# set("OpenCV_DIR" "/modules/opencv/3.4.1/share/OpenCV/")
set(CMAKE_PREFIX_PATH "/usr/local/Cellar/opencv#3/")
set(OpenCV_INCLUDE_DIRS "/usr/local/Cellar/opencv#3/include/")
set(OpenCV_LIBS "/usr/local/Cellar/opencv#3/lib/")
find_package(OpenCV REQUIRED)
message(STATUS "OpenCV library status:")
message(STATUS " version: ${OpenCV_VERSION}")
message(STATUS " libraries: ${OpenCV_LIBS}")
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")
if(UNIX)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=gnu++0x")
endif()
set(CMAKE_C_COMPILER "/usr/local/Cellar/llvm/6.0.0/bin/clang")
set(CMAKE_CXX_COMPILER "/usr/local/Cellar/llvm/6.0.0/bin/clang++")
set(OPENMP_LIBRARIES "/usr/local/Cellar/llvm/6.0.0/lib")
set(OPENMP_INCLUDES "/usr/local/Cellar/llvm/6.0.0/include")
OPTION (USE_OpenMP "Use OpenMP to enamble <omp.h>" ON)
# Find OpenMP
if(APPLE AND USE_OpenMP)
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
set(OpenMP_C "${CMAKE_C_COMPILER}")
set(OpenMP_C_FLAGS "-fopenmp=libomp -Wno-unused-command-line-argument")
set(OpenMP_C_LIB_NAMES "libomp" "libgomp" "libiomp5")
set(OpenMP_libomp_LIBRARY ${OpenMP_C_LIB_NAMES})
set(OpenMP_libgomp_LIBRARY ${OpenMP_C_LIB_NAMES})
set(OpenMP_libiomp5_LIBRARY ${OpenMP_C_LIB_NAMES})
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(OpenMP_CXX "${CMAKE_CXX_COMPILER}")
set(OpenMP_CXX_FLAGS "-fopenmp=libomp -Wno-unused-command-line-argument")
set(OpenMP_CXX_LIB_NAMES "libomp" "libgomp" "libiomp5")
set(OpenMP_libomp_LIBRARY ${OpenMP_CXX_LIB_NAMES})
set(OpenMP_libgomp_LIBRARY ${OpenMP_CXX_LIB_NAMES})
set(OpenMP_libiomp5_LIBRARY ${OpenMP_CXX_LIB_NAMES})
endif()
endif()
if(USE_OpenMP)
find_package(OpenMP REQUIRED)
endif(USE_OpenMP)
if (OPENMP_FOUND)
include_directories("${OPENMP_INCLUDES}")
link_directories("${OPENMP_LIBRARIES}")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
# set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
endif(OPENMP_FOUND)
include_directories( ${OpenCV_INCLUDE_DIRS} )
target_link_libraries( MyOpenCVTest ${OpenCV_LIBS})
TARGET_LINK_LIBRARIES(MyOpenCVTest opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs)
You might want to set e.g. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lpthread") such that the linker automatically detects the appropriate pthread library
Do
brew reinstall llvm
to install llvm compiler.
Please note that, you can't use gcc compiler on Mac-Sierra for your project which needs openMP and also openCV. You need to use llvm compiler.
Verify the correct location of llvm and openCV installation directory.
I'm on Windows 10 and got this error when generating solution using CMake-GUI:
CMake Warning at C:/Program Files/CMake/share/cmake-3.8/Modules/FindBoost.cmake:765 (message):
Imported targets not available for Boost version
Call Stack (most recent call first):
C:/Program Files/CMake/share/cmake-3.8/Modules/FindBoost.cmake:869 (_Boost_COMPONENT_DEPENDENCIES)
C:/Program Files/CMake/share/cmake-3.8/Modules/FindBoost.cmake:1472 (_Boost_MISSING_DEPENDENCIES)
I know it's been asked and answered here CMake finds Boost but the imported targets not available for Boost version
but the solution in there (upgrading CMake) doesn't work for me, still get the same error after upgrading from 3.7 to 3.8
Update
My boost version is 106300.
Content of CMakeList file is below:
# doc/CMakeLists.txt uses configure_file behavior from CMake 2.8
cmake_minimum_required(VERSION 2.8)
project(tpie)
include_directories(.)
add_definitions(-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE)
#### CONFIG.H Checks:
include(CheckIncludeFiles)
if(NOT WIN32)
add_definitions("-Wall -Wextra")
endif(NOT WIN32)
if(WIN32)
add_definitions("-DWIN32_LEAN_AND_MEAN /bigobj")
endif(WIN32)
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/")
#### Dependencies
## Boost
set(Boost_ADDITIONAL_VERSIONS "1.40.0" "1.40" "1.41" "1.41.0" "1.42" "1.42.0" "1.43" "1.43.0" "1.44" "1.44.0" "1.45" "1.45.0")
set(Boost_USE_MULTITHREADED ON)
if(WIN32)
set(Boost_USE_STATIC_LIBS ON)
endif(WIN32)
find_package(Boost COMPONENTS date_time filesystem system REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
link_directories( ${Boost_LIBRARY_DIRS} )
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
if(TPIE_FRACTIONDB_DIR_INL)
include_directories(${TPIE_FRACTIONDB_DIR_INL})
endif(TPIE_FRACTIONDB_DIR_INL)
check_include_files("unistd.h" TPIE_HAVE_UNISTD_H)
check_include_files("sys/unistd.h" TPIE_HAVE_SYS_UNISTD_H)
# Ryan Pavlik's Git revision description helper
# http://stackoverflow.com/a/4318642
include(GetGitRevisionDescription)
get_git_head_revision(GIT_REFSPEC GIT_COMMIT)
## Snappy
option(TPIE_USE_SNAPPY "Use Snappy, a fast compressor/decompressor" ON)
if(TPIE_USE_SNAPPY)
find_package(Snappy)
if(${Snappy_FOUND})
set(TPIE_HAS_SNAPPY ON)
include_directories(${Snappy_INCLUDE_DIR})
else(${Snappy_FOUND})
set(TPIE_HAS_SNAPPY OFF)
endif(${Snappy_FOUND})
endif(TPIE_USE_SNAPPY)
#### Installation paths
#Default paths
set(BIN_INSTALL_DIR bin)
set(LIB_INSTALL_DIR lib)
set(HEADERS_INSTALL_DIR include/tpie)
if (WIN32)
set(DOC_INSTALL_DIR doc)
else(WIN32)
set(DOC_INSTALL_DIR "share/doc/tpie")
endif(WIN32)
set(INSTALL_TARGETS_DEFAULT_ARGS
RUNTIME DESTINATION ${BIN_INSTALL_DIR}
LIBRARY DESTINATION ${LIB_INSTALL_DIR}
ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
if (CMAKE_BUILD_TYPE)
string(TOUPPER ${CMAKE_BUILD_TYPE} bt)
string(REGEX MATCH " -DNDEBUG " TPIE_NDEBUG " ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${bt}} ")
else()
option(TPIE_NDEBUG "Disable debugging information" ON)
endif()
set(TPIE_S ${CMAKE_CURRENT_SOURCE_DIR})
set(TPIE_B ${CMAKE_CURRENT_BINARY_DIR})
if(NOT WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tpie/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/tpie/config.h)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/tpie/config.h DESTINATION ${HEADERS_INSTALL_DIR})
add_subdirectory(tpie)
add_subdirectory(doc)
option(COMPILE_TEST "Compile test programs" ON)
option(TPL_LOGGING "Enable tpie logging." ON)
option(TPIE_DEPRECATED_WARNINGS "Enable warnings for deprecated classes, methods and typedefs" OFF)
option(TPIE_PARALLEL_SORT "Enable parallel quick sort implementation" ON)
if (COMPILE_TEST)
ENABLE_TESTING()
add_subdirectory(test)
add_subdirectory(apps)
endif (COMPILE_TEST)
include(InstallRequiredSystemLibraries)
set(CPACK_PACKAGE_CONTACT "rav#cs.au.dk")
set(CPACK_GENERATOR TGZ)
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "TPIE")
set(CPACK_PACKAGE_VENDOR "The TPIE maintainers")
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING.md")
set(CPACK_PACKAGE_VERSION_MAJOR "1")
set(CPACK_PACKAGE_VERSION_MINOR "1")
set(CPACK_PACKAGE_VERSION_PATCH "0")
set(CPACK_PACKAGE_INSTALL_DIRECTORY "TPIE ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}")
if(WIN32 AND NOT UNIX)
# There is a bug in NSI that does not handle full unix paths properly. Make
# sure there is at least one set of four (4) backlasshes.
#set(CPACK_PACKAGE_ICON "${CMake_SOURCE_DIR}/Utilities/Release\\\\InstallIcon.bmp")
set(CPACK_NSIS_DISPLAY_NAME "${CPACK_PACKAGE_INSTALL_DIRECTORY} ${CPACK_PACKAGE_DESCRIPTION_SUMMARY}")
set(CPACK_NSIS_HELP_LINK "http:\\\\\\\\thomasmoelhave.github.com/tpie/")
set(CPACK_NSIS_URL_INFO_ABOUT "http:\\\\\\\\thomasmoelhave.github.com/tpie/")
set(CPACK_NSIS_CONTACT ${CPACK_PACKAGE_CONTACT})
set(CPACK_NSIS_MODIFY_PATH ON)
list(APPEND CPACK_GENERATOR NSIS)
else(WIN32 AND NOT UNIX)
list(APPEND CPACK_GENERATOR DEB)
endif(WIN32 AND NOT UNIX)
install(DIRECTORY tpie
DESTINATION include
FILES_MATCHING REGEX "\\.h$|\\.inl$"
PATTERN "deadcode" EXCLUDE)
install(DIRECTORY share/tpie
DESTINATION share)
include(CPack)
Any other idea? tks
Your CMAKE is too old for the boost 1.63.
Reinstall a newer CMAKE or do this(according to FindBoost.cmake source code in cmake/share/cmake-3.9/Modules/FindBoost.cmake line 516):
Note: to add a new Boost release, run
% cmake -DBOOST_DIR=/path/to/boost/source -P Utilities/Scripts/BoostScanDeps.cmake
Or, Just modify that line from
elseif(NOT Boost_VERSION VERSION_LESS 106200 AND Boost_VERSION VERSION_LESS 106300)
to
elseif(NOT Boost_VERSION VERSION_LESS 106200 AND Boost_VERSION VERSION_LESS 106500)
I'm running Ubuntu 15.10 with CUDA 7.5. CMmake is v3.2.2, NVCC is release 7.5, v7.5.17; GCC is Ubuntu 5.2.1-22ubuntu2 v5.2.1
Triggering C++11 in regular projects is easy with:
project(foo CXX)
set(TARGET foo CMAKE_CXX_STANDARD 11)
I'm defining my CUDA project with:
find_package(CUDA REQUIRED)
CUDA_ADD_EXECUTABLE(foo ${foo_src} ${foo_hdr} ${foo_cu})
But the C++11 support doesn't get propagated to NVCC. I have to add:
list(APPEND CUDA_NVCC_FLAGS "-std=c++11")
This seems like a kludge. There was evidently work on this recently according to this task, but I haven't been able to find the results.
How do I get CMake to automatically set the C++11 flags when declaring the project as C++11?
EDIT: I've retuned to to this question with CUDA 8.0 and CMake 3.5.1.
From the documentation, set(CUDA_PROPAGATE_HOST_FLAGS ON) will propagate the contents of CMAKE_CXX_FLAGS, so the following triggers C++11 for both cpp and nvcc:
set (CMAKE_CXX_FLAGS "--std=c++11")
set (CUDA_PROPAGATE_HOST_FLAGS ON)
However, set(CMAKE_CXX_STANDARD 11) does not impact CMAKE_CXX_FLAGS, so the following gives compiler errors for C++11 device code, as there's nothing to propagate:
set (CMAKE_CXX_STANDARD 11)
set (CUDA_PROPAGATE_HOST_FLAGS ON)
I can't seem to find a combination of CMake commands that avoids explicitly setting --std=c++11 in either CXX or CUDA flags.
Since CMake 3.8 (since CMake supports CUDA as a language) there is a new target property CUDA_STANDARD. Although its name is quite confusing, it adds the -std=XXX to the nvcc compile command.
With a recent CMake version the proper way would be
cmake_minimum_required(VERSION 3.8.2)
enable_language(CUDA)
add_executable(foo ${foo_src} ${foo_cu})
set_property(TARGET foo PROPERTY CUDA_STANDARD 11)
I'm writing a Python extension module in C++ using Boost.Python. However, I
would like to use a newer version of the Boost library than the system
installation offers. This newer version of boost is contained in
BOOST_ROOT=$HOME/opt/boost/1.55.0.
Following this guide on how
to use RPath in CMake I came up with the following CMakeLists.txt.
cmake_minimum_required(VERSION 2.8)
project("test")
set(PROJECT_DESC "Test Boost.Python")
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
add_definitions(-std=c++11 -Wall -Wextra -pedantic)
find_package(PythonInterp REQUIRED)
find_package(PythonLibsNew REQUIRED)
find_package(Boost COMPONENTS python REQUIRED)
message(STATUS "Using Boost installation in:")
message(STATUS " INCLUDE: ${Boost_INCLUDE_DIRS}")
message(STATUS " LIB: ${Boost_LIBRARIES}")
include_directories(
${PROJECT_SOURCE_DIR}
${PYTHON_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS}
)
macro(add_python_module _name _srccpp)
PYTHON_ADD_MODULE(${_name} ${_srccpp})
target_link_libraries(${_name} ${Boost_LIBRARIES})
endmacro()
add_python_module(ownership ownership.cpp)
Then I run the following commands to build the module
mkdir build; cd build
cmake -DCMAKE_INSTALL_PATH="$BOOST_ROOT/lib" ..
make
The status message after running cmake points to the right boost
installation. (The CMake boost module picks up the environment variable
$BOOST_ROOT) I.e. the CMake variable Boost_LIBARIES points to
$BOOST_ROOT/lib/libboost_python.so.
But, if I check which libraries would actually be used, the system libraries
are listed:
$ ldd ownership.so
# ...
libboost_python.so.1.53.0 => /usr/lib64/libboost_python.so.1.53.0 (0x00007f09abfc1000)
# ...
This is version 1.53, even though the status message above explicitely pointed
to 1.55.
What am I doing wrong? How can I get ldd to pick the library in
$BOOST_ROOT/lib/libboost_python.so.1.55.0?
First of all as I already mentioned in commens you don't need to use CMake RPATH-manipulations
options. Example: http://pastebin.com/UDyYbQ1d, output: standard and custom
Do you know of a way of convincing CMake otherwise even if LIBRARY_PATH is set
This issue is not related to CMake, it's compiler responsibility. Read this discussion.
Solution
You can clear LIBRARY_PATH if you set BOOST_ROOT variable explicitly. And you can check
environment variable in CMakeLists.txt to avoid this problem in future:
string(COMPARE NOTEQUAL "$ENV{LIBRARY_PATH}" "" library_path_warning)
if(library_path_warning)
message(
WARNING
"LIBRARY_PATH environment variable is not empty ($ENV{LIBRARY_PATH}) "
"This may cause dynamic linking errors!"
)
endif()