Compiling and linking against OpenMP with AppleClang on Mac OS X Mojave - c++

I've been trying to compile a simple OpenMP program using AppleClang on Mac OS X 10.14.5 Mojave with the CLion IDE.
main.cpp:
#include <omp.h>
#include <iostream>
int main() {
std::cout << omp_get_max_threads() << std::endl;
return 1;
}
CMakeLists.txt:
cmake_minimum_required(VERSION 3.14)
project(OpenMPTest)
set(CMAKE_CXX_STANDARD 17)
add_executable(OpenMPTest main.cpp)
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()
CMake output:
/Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - Unix Makefiles" /Users/bully/CLionProjects/OpenMPTest
-- The C compiler identification is AppleClang 10.0.1.10010046
-- The CXX compiler identification is AppleClang 10.0.1.10010046
-- 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: -Xclang -fopenmp (found version "3.1")
-- Found OpenMP_CXX: -Xclang -fopenmp (found version "3.1")
-- Found OpenMP: TRUE (found version "3.1")
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/bully/CLionProjects/OpenMPTest/cmake-build-debug
When I build the project, I receive a linker error:
====================[ Build | all | Debug ]=====================================
/Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake --build /Users/bully/CLionProjects/OpenMPTest/cmake-build-debug --target all -- -j 2
Scanning dependencies of target OpenMPTest
[ 50%] Building CXX object CMakeFiles/OpenMPTest.dir/main.cpp.o
[100%] Linking CXX executable OpenMPTest
Undefined symbols for architecture x86_64:
"_omp_get_max_threads", referenced from:
_main in main.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [OpenMPTest] Error 1
make[1]: *** [CMakeFiles/OpenMPTest.dir/all] Error 2
make: *** [all] Error 2
How come this does not work? From the command line I can run clang++ main.cpp -lomp successfully after installing the library headers with open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg.
message(STATUS "Linker flags:" "${OpenMP_EXE_LINKER_FLAGS}") prints:
-- Linker flags:
If I replace the CMAKE_EXE_LINKER_FLAGS setter with set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lomp") compilation with linking works. Why do I have to specify this manually? What's the preferred way of getting this to work in a platform-independent way? -fopenmp yields clang: error: unsupported option '-fopenmp'. gcc and MSVC on Linux and Windows respectively played nice with the CMake OpenMP configuration but Mac OS X does not.

As commented by Tsyvarev, the solution is to use the "updated" way of including OpenMP in CMake:
cmake_minimum_required(VERSION 3.14)
project(OpenMPTest)
set(CMAKE_CXX_STANDARD 17)
add_executable(OpenMPTest main.cpp)
find_package(OpenMP REQUIRED) # Find the package
target_link_libraries(${PROJECT_NAME} ${OpenMP_CXX_LIBRARIES}) # Link against it for C++
This compiled on Windows, Ubuntu and Mac OS X using their platform's default compilers respectively.
The accepted answer here is not recommended even though it also has the most upvotes.

Related

Cmake is finding GSL but I can't include gsl in my C++ script

Why does Cmake find the library but I can't include it?
I am trying to use the gsl library in C++ but I get gsl/gsl_sf_bessel.h: No such file or directory when I run cmake --build even though it says -- Found GSL: /usr/include (found version "2.7.1") in the terminal after running cmake ...
I am using Ubuntu 22.04
I installed gsl with sudo apt-get install libgsl-dev and it is in /usr/include.
I think it might be a problem with the compiler I am using but I'm not sure how to check.
My CMakeLists.txt file
cmake_minimum_required(VERSION 3.5.1)
project(mujoco_gym)
set(CMAKE_CXX_STANDARD 14)
# It prevents the decay to C++98 when the compiler does not support C++14
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# It disables the use of compiler-specific extensions
# e.g. -std=c++14 rather than -std=gnu++14
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
find_package(GSL REQUIRED)
link_libraries(GSL::gsl)
include_directories(${PROJECT_SOURCE_DIR})
file(GLOB SOURCE_FILES mujoco_gym.cpp)
add_executable(${CMAKE_PROJECT_NAME} ${SOURCE_FILES})
target_link_libraries (
${CMAKE_PROJECT_NAME}
${GSL_LIBRARIES}
)
My .cpp file.
#include<stdbool.h> //for bool
#include "stdlib.h"
#include "string.h"
#include <iostream>
#include <gsl/gsl_sf_bessel.h>
int main()
{
double x = 5.0;
std::cout << gsl_sf_bessel_j0(x);
return 0;
}
Cmake and build in the terminal
$ cmake ..
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /home/iii/miniconda3/envs/tf/bin/x86_64-conda-linux-gnu-cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /home/iii/miniconda3/envs/tf/bin/x86_64-conda-linux-gnu-c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.2")
-- Found GSL: /usr/include (found version "2.7.1")
-- Configuring done
-- Generating done
-- Build files have been written to: /home/iii/.mujoco/mujoco210/sample/build
$ cmake --build . --config Release
[ 50%] Building CXX object CMakeFiles/mujoco_gym.dir/mujoco_gym.cpp.o
/home/iii/.mujoco/mujoco210/sample/mujoco_gym.cpp:21:10: fatal error: gsl/gsl_sf_bessel.h: No such file or directory
21 | #include <gsl/gsl_sf_bessel.h>
| ^~~~~~~~~~~~~~~~~~~~~
compilation terminated.
gmake[2]: *** [CMakeFiles/mujoco_gym.dir/build.make:76: CMakeFiles/mujoco_gym.dir/mujoco_gym.cpp.o] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/mujoco_gym.dir/all] Error 2
gmake: *** [Makefile:91: all] Error 2
$

cmake SHARED lib led to clang: error: linker command failed

On macOS I'm trying to build my own small library based on fmt, while installing it with vcpkg and building the project with cmake.
CMakeLists.txt
cmake_minimum_required(VERSION 3.19.1)
set(CMAKE_TOOLCHAIN_FILE ~/vcpkg/scripts/buildsystems/vcpkg.cmake)
project(MYLIB)
set (CMAKE_CXX_STANDARD 14)
find_package(fmt REQUIRED)
include_directories(~/vcpkg/installed/x64-osx/include)
add_library(mylib mylib.cpp)
mylib.cpp
#include "mylib.h"
#include <fmt/core.h>
float add(float a, float b)
{
fmt::print("Hello MYLIB, world!\n");
return (a + b);
}
With the above I can build the static flavor of it. But it fails while trying to build the SHARED version with
add_library(mylib SHARED mylib.cpp)
which led to:
user#users-MacBook-Pro build % rm -Rf *
zsh: sure you want to delete all 4 files in /Users/user/mylib/build [yn]? y
user#users-MacBook-Pro build % cmake ..
-- The C compiler identification is AppleClang 12.0.0.12000032
-- The CXX compiler identification is AppleClang 12.0.0.12000032
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/user/mylib/build
user#users-MacBook-Pro build % make
Scanning dependencies of target mylib
[ 50%] Building CXX object CMakeFiles/mylib.dir/mylib.cpp.o
[100%] Linking CXX shared library libmylib.dylib
Undefined symbols for architecture x86_64:
"fmt::v8::vprint(fmt::v8::basic_string_view<char>, fmt::v8::basic_format_args<fmt::v8::basic_format_context<fmt::v8::appender, char> >)", referenced from:
add(float, float) in mylib.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [libmylib.dylib] Error 1
make[1]: *** [CMakeFiles/mylib.dir/all] Error 2
make: *** [all] Error 2

CMAKE MAC OSX library linking Issue: compiles on Linux but on on Mac

I am trying to compile my code with CMake. But when I do the make command I get the following error:
[ 17%] Linking CXX shared library libglobal.so
Apple LLVM version 9.1.0 (clang-902.0.39.1)
Target: x86_64-apple-darwin17.5.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -lto_library /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libLTO.dylib -dynamic -dylib -arch x86_64 -dylib_install_name #rpath/libglobal.so -macosx_version_min 10.13.0 -o libglobal.so -L/opt/local/lib -L/Users/George/Documents/root/build/lib -lc++ -headerpad_max_install_names CMakeFiles/global.dir/RawHitPeta6.cpp.o CMakeFiles/global.dir/CorrectedHit.cpp.o CMakeFiles/global.dir/CalibrationSettings.cpp.o CMakeFiles/global.dir/Coincidence.cpp.o CMakeFiles/global.dir/AnalysisSettings.cpp.o CMakeFiles/global.dir/Plot.cpp.o CMakeFiles/global.dir/Destination.cpp.o CMakeFiles/global.dir/Crystal.cpp.o CMakeFiles/global.dir/Geometry.cpp.o CMakeFiles/global.dir/geometries/TwoModuleSetup.cpp.o CMakeFiles/global.dir/geometries/P6EvaluationBoard.cpp.o CMakeFiles/global.dir/geometries/SystemSingleLayer7.cpp.o CMakeFiles/global.dir/geometries/SystemSingleLayer8.cpp.o CMakeFiles/global.dir/geometries/SystemDualLayer.cpp.o CMakeFiles/global.dir/geometries/SystemHighResolutionDualLayer.cpp.o CMakeFiles/global.dir/geometries/SystemHighResolutionDualLayerLong.cpp.o -lc++ -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/9.1.0/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
"TVersionCheck::TVersionCheck(int)", referenced from:
__GLOBAL__sub_I_Plot.cpp in Plot.cpp.o
__GLOBAL__sub_I_Destination.cpp in Destination.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [Analysis/global/libglobal.so] Error 1
make[1]: *** [Analysis/global/CMakeFiles/global.dir/all] Error 2
make: *** [all] Error 2
I already looked for ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation).
This is the cmake outout I get:
CMake Warning (dev):
Policy CMP0042 is not set: MACOSX_RPATH is enabled by default. Run "cmake
--help-policy CMP0042" for policy details. Use the cmake_policy command to
set the policy and suppress this warning.
MACOSX_RPATH is not specified for the following targets:
coincidencePlots
correctedHitPlots
generalPlots
global
processing
rawHitPlots
This warning is for project developers. Use -Wno-dev to suppress it.
-- Generating done
-- Build files have been written to: /Users/George/Desktop/petaAnalysis/build
I already looked for ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation). But I could not find anything useful, that helped.
This is the cmake output I get:
CMake Warning (dev):
Policy CMP0042 is not set: MACOSX_RPATH is enabled by default. Run "cmake
--help-policy CMP0042" for policy details. Use the cmake_policy command to
set the policy and suppress this warning.
MACOSX_RPATH is not specified for the following targets:
coincidencePlots
correctedHitPlots
generalPlots
global
processing
countRawPlots
This warning is for project developers. Use -Wno-dev to suppress it.
-- Generating done
-- Build files have been written to: /Users/Hans/Desktop/Project/build
I tried to run the code on linux. There it seems works fine. I think it is a linking problem between the shared libraries I created.
This is are the CMAKE-files:
File 1(in main directory):
cmake_minimum_required(VERSION 2.8)
project(Analysis)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${Analysis_SOURCE_DIR}/bin)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -stdlib=libc++ -lstdc++ -std=c++14 -m64 -I/Users/George/Documents/root/build/include")
#SET(CMAKE_BUILD_WITH_INSTALL_RPATH true)
#SET(CMAKE_INSTALL_RPATH "$ORIGIN/")
SET(CMAKE_SYSTEM_NAME Darwin)
# Add MacPorts
INCLUDE_DIRECTORIES(/opt/local/include)
LINK_DIRECTORIES(/opt/local/lib)
ADD_SUBDIRECTORY(Analysis)
ADD_SUBDIRECTORY(CrystalMapGenerator)
ADD_SUBDIRECTORY(CoincidenceBrowser)
ADD_SUBDIRECTORY(FunctionTests)
ADD_SUBDIRECTORY(AnalysisResultExtractor)
ADD_SUBDIRECTORY(AnalysisComparison)
ADD_SUBDIRECTORY(SDIPRawDataDebug)
ADD_SUBDIRECTORY(GateDataTimeCalibrationTester)
File 2(in subdirectory):
cmake_minimum_required(VERSION 2.8)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${Analysis_SOURCE_DIR}/bin)
if(UNIX)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=gnu++0x")
endif()
#set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_BUILD_TYPE Release)
# Add information on ROOT libraries
INCLUDE(../FindROOT.cmake)
INCLUDE_DIRECTORIES( ${ROOTSYS}/include)
LINK_DIRECTORIES( ${ROOTSYS}/lib)
ADD_SUBDIRECTORY(processing)
ADD_SUBDIRECTORY(generalPlots)
ADD_SUBDIRECTORY(rawHitPlots)
ADD_SUBDIRECTORY(correctedHitPlots)
ADD_SUBDIRECTORY(coincidencePlots)
ADD_SUBDIRECTORY(global)
include_directories("processing")
include_directories("generalPlots")
include_directories("rawHitPlots")
include_directories("correctedHitPlots")
include_directories("coincidencePlots")
include_directories("global")
set(SOURCES
DataChain.cpp
main.cpp
)
ADD_EXECUTABLE(analysis ${SOURCES})
target_link_libraries(analysis processing generalPlots rawHitPlots correctedHitPlots coincidencePlots global ${ROOT_LIBRARIES} -lSpectrum -lMinuit)
File3(in folder of library global):
cmake_minimum_required(VERSION 2.8)
INCLUDE(../../FindROOT.cmake)
INCLUDE_DIRECTORIES( ${ROOT_INCLUDE_DIR})
LINK_DIRECTORIES( ${ROOT_LIBRARY_DIR})
ADD_LIBRARY(global SHARED
RawHitPeta6.cpp
CorrectedHit.cpp
CalibrationSettings.cpp
Coincidence.cpp
AnalysisSettings.cpp
Plot.cpp
Destination.cpp
Crystal.cpp
Geometry.cpp
geometries/TwoModuleSetup.cpp
geometries/P6EvaluationBoard.cpp
geometries/SystemSingleLayer7.cpp
geometries/SystemSingleLayer8.cpp
geometries/SystemDualLayer.cpp
geometries/SystemHighResolutionDualLayer.cpp
geometries/SystemHighResolutionDualLayerLong.cpp
)
Thanks alot!
If you're using a recent version of ROOT5 or ROOT6, instead of writing or downloading a FindROOT.cmake, use the info that ROOT auto-generates for you when your (or your package system) builds it.
In your ROOT installation, find the directory that holds ROOTConfig.cmake. Add that directory to your CMAKE_MODULE_PATH. Then, call find_package(ROOT).
A basic CMakeLists.txt could look like this:
cmake_minimum_required(VERSION 3.10.2 FATAL_ERROR)
execute_process(COMMAND root-config --prefix
COMMAND tr -d \\n
RESULT_VARIABLE RC_RESULT
OUTPUT_VARIABLE ROOT_PREFIX)
list(APPEND CMAKE_MODULE_PATH "${ROOT_PREFIX}/share/root/cmake")
find_package(ROOT)
include(CMakePrintHelpers)
cmake_print_variables(ROOT_FOUND ROOT_LIBRARIES ROOT_INCLUDE_DIRS)
Running cmake with that results in:
~/rt
❯ cmake .
-- The C compiler identification is AppleClang 9.1.0.9020039
-- The CXX compiler identification is AppleClang 9.1.0.9020039
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/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: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- ROOT_FOUND="1" ; ROOT_LIBRARIES="/usr/local/lib/root/libCore.so;/usr/local/lib/root/libImt.so;/usr/local/lib/root/libRIO.so;/usr/local/lib/root/libNet.so;/usr/local/lib/root/libHist.so;/usr/local/lib/root/libGraf.so;/usr/local/lib/root/libGraf3d.so;/usr/local/lib/root/libGpad.so;/usr/local/lib/root/libTree.so;/usr/local/lib/root/libTreePlayer.so;/usr/local/lib/root/libRint.so;/usr/local/lib/root/libPostscript.so;/usr/local/lib/root/libMatrix.so;/usr/local/lib/root/libPhysics.so;/usr/local/lib/root/libMathCore.so;/usr/local/lib/root/libThread.so;/usr/local/lib/root/libMultiProc.so" ; ROOT_INCLUDE_DIRS="/usr/local/include/root"
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/nega/rt
~/rt
❯
You'll notice that ROOT_FOUND has been set to TRUE, and ROOT_LIBRARIES, and ROOT_INCLUDE_DIRS have been populated. You can now use those variables to setup your compilation and linking.

Qt Project using cmake in CLion C++

To be honest im not a fan of Qt Creator. So I decided to use another IDE like CLion. I researched and found out that Clion doesnt support qmake, but it is possible to get a Qt-Project to run with cmake.
Thats my CMakeList. CLion don't give me any error when i save this make-file.
cmake_minimum_required(VERSION 3.8)
project(Qt_CmakeTest)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
find_package(Qt5Core REQUIRED)
find_package(Qt5Widgets REQUIRED)
add_executable(Qt_CmakeTest ${SOURCE_FILES})
target_link_libraries(Qt_CmakeTest Qt5::Core Qt5::Widgets)
to test if it worked I created a simple cpp.
#include <iostream>
#include <QApplication>
using namespace std;
int main(int argc, char **argv)
{
QApplication app(argc,argv);
return app.exec();
}
I tried to implement it following these instructions
How to configure CLion IDE for Qt Framework?
I have to use the cmake binary that qt provides. So I set the Cmake Option to:
-DCMAKE_PREFIX_PATH=C:\Qt\Qt5.9.1\5.9.1\mingw53_32\lib\cmake
But if I try to compile it it gives me this error:
"C:\Program Files\JetBrains\CLion 2017.2.2\bin\cmake\bin\cmake.exe" --build
C:\Users\Marcel\Desktop\Projekte\Qt\Qt-CmakeTest\cmake-build-debug --target Qt_CmakeTest -- -j 2
[ 50%] Linking CXX executable Qt_CmakeTest.exe
CMakeFiles\Qt_CmakeTest.dir/objects.a(main.cpp.obj): In function `main':
C:/Users/Marcel/Desktop/Projekte/Qt/Qt-CmakeTest/main.cpp:7: undefined reference to `_imp___ZN12QApplicationC1ERiPPci'
C:/Users/Marcel/Desktop/Projekte/Qt/Qt-CmakeTest/main.cpp:8: undefined reference to `_imp___ZN12QApplication4execEv'
C:/Users/Marcel/Desktop/Projekte/Qt/Qt-CmakeTest/main.cpp:7: undefined reference to `_imp___ZN12QApplicationD1Ev'
C:/Users/Marcel/Desktop/Projekte/Qt/Qt-CmakeTest/main.cpp:7: undefined reference to `_imp___ZN12QApplicationD1Ev'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [Qt_CmakeTest.exe] Error 1
CMakeFiles\Qt_CmakeTest.dir\build.make:99: recipe for target 'Qt_CmakeTest.exe' failed
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/Qt_CmakeTest.dir/all' failed
CMakeFiles\Makefile2:78: recipe for target 'CMakeFiles/Qt_CmakeTest.dir/rule' failed
Makefile:117: recipe for target 'Qt_CmakeTest' failed
mingw32-make.exe[2]: *** [CMakeFiles/Qt_CmakeTest.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles/Qt_CmakeTest.dir/rule] Error 2
mingw32-make.exe: *** [Qt_CmakeTest] Error 2
I downloaded different versions of Qt because Qt 5.9 uses Mingw 5.3 and CLion says I'm using Mingw 5.0 and at the beginning I used Qt 5.6 and it used Mingw 4.9. I can't really figure out why it is not working.
A clean CMake Build looks like this
"C:\Program Files\JetBrains\CLion 2017.2.2\bin\cmake\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles" C:\Users\Marcel\Desktop\Projekte\Qt\Qt-CmakeTest
-- The C compiler identification is GNU 6.3.0
-- The CXX compiler identification is GNU 6.3.0
-- Check for working C compiler: C:/MinGW/bin/gcc.exe
-- Check for working C compiler: C:/MinGW/bin/gcc.exe -- 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: C:/MinGW/bin/g++.exe
-- Check for working CXX compiler: C:/MinGW/bin/g++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/Marcel/Desktop/Projekte/Qt/Qt-CmakeTest/cmake-build-debug
[Finished]
Somehow there was no PATH to the Qt binary. I have added the PATH and rebuild the cmake Project and it worked. So it was just a matter of the path and of the versions.

C++ cmake & boost & arm cross compilation

I have a problem with compiling my program with boost and cmake. I use cross-compilation with using gcc-linaro-arm-linux-gnueabihf-4.9/bin/arm-linux-gnueabihf-g++ compiler.
And now I have cmake file like:
cmake_minimum_required (VERSION 2.6.2)
project (xxx)
SET(CMAKE_CXX_COMPILER /home/kamil/gcc-linaro-arm-linux-gnueabihf-4.9/bin/arm-linux-gnueabihf-g++)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread -Dtypeof=__typeof__ -D_GLIBCXX_USE_CXX11_ABI=0 -Wall -Werror -Wextra -Wno-error=array-bounds")
if(DEFINED ENV{SDKTARGETSYSROOT})
set(CMAKE_FIND_ROOT_PATH $ENV{SDKTARGETSYSROOT})
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
endif(DEFINED ENV{SDKTARGETSYSROOT})
find_package(Boost COMPONENTS system filesystem REQUIRED)
include_directories("/usr/local/include")
include_directories(${Boost_INCLUDE_DIRS})
enable_testing()
set(CMAKE_CTEST_COMMAND ctest -V)
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} )
add_subdirectory(src)
add_subdirectory(test EXCLUDE_FROM_ALL)
and
add_executable(xxxx
main.cpp
...cpp
...cpp
...cpp
...cpp
)
target_link_libraries(xxxx
${Boost_SYSTEM_LIBRARY}
${Boost_THREAD_LIBRARY}
)
install(TARGETS xxxx
DESTINATION bin
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE
)
And now when use commands in linux(Ubuntu):
cmake ..
make
I have response at:
kamil#kamil:~/test/build$ rm -rf *
kamil#kamil:~/test/build$ cmake ..
-- The C compiler identification is GNU 4.8.4
-- The CXX compiler identification is GNU 4.8.4
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Boost version: 1.55.0
-- Found the following Boost libraries:
-- system
-- filesystem
-- Found GTest: /usr/local/lib/libgtest.so
-- Configuring done
-- Generating done
-- Build files have been written to: /home/kamil/test/build
kamil#kamil:~/test/build$ make
Scanning dependencies of target xxxx
[ 12%] Building CXX object src/CMakeFiles/test.dir/main.cpp.o
In file included from /home/test/src/test/utils/logger.hpp:4:0,
from /home/kamil/test/src/main.cpp:9:
/home/kamil/test/src/test/utils/singleton.hpp:5:33: fatal error: boost/noncopyable.hpp: No such file or directory
#include <boost/noncopyable.hpp>
^
compilation terminated.
make[2]: *** [src/CMakeFiles/test.dir/main.cpp.o] Error 1
make[1]: *** [src/CMakeFiles/test.dir/all] Error 2
make: *** [all] Error 2
Error:
fatal error: boost/noncopyable.hpp: No such file or directory
#include <boost/noncopyable.hpp>
When I comment on the following line in cmake:
SET(CMAKE_CXX_COMPILER /home/kamil/toradex/gcc-linaro-arm-linux-gnueabihf-4.9/bin/arm-linux-gnueabihf-g++)
then everything is ok.
I install boost in Ubuntu with command: sudo apt-get install libboost1.55-all-dev
What is wrong with compiling with linux-gnueabihf-g++ and how to fix it.
Compiling boost with gcc-linaro-arm-linux-gnueabihf-4.9 worked.
Helps link: http://www.cnx-software.com/2011/10/03/cross-compiling-boost-c-libraries-for-arm/