I'm trying to execute my homework in C++ with OpenMP on Mac with macOS Mojave. But it's failed. The Mac is new, so all setups are not changed. What I did:
I installed Homebrew.
I installed llvm (brew install llvm)
I installed omp (brew install libomp)
Also, in CMakeLists.txt of the project I have
cmake_minimum_required(VERSION 3.5.1)
project(...)
include_directories("/usr/local/include" "/usr/local/opt/llvm/include")
link_directories("/usr/local/lib" "/usr/local/opt/llvm/lib")
set(CMAKE_CXX_COMPILER /usr/local/opt/llvm/bin/clang++)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native -fopenmp -O3")
add_executable(...)
In Terminal 'clang -v':
Apple LLVM version 10.0.1 (clang-1001.0.46.4)
Target: x86_64-apple-darwin18.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
'gcc -v':
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/c++/4.2.1
Apple LLVM version 10.0.1 (clang-1001.0.46.4)
Target: x86_64-apple-darwin18.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
In CLion I have this error:
[ 25%] Linking CXX executable search
ld: unknown option: -platform_version
clang-10: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [search] Error 1
make[2]: *** [CMakeFiles/search.dir/all] Error 2
make[1]: *** [CMakeFiles/search.dir/rule] Error 2
make: *** [search] Error 2
I re-read a lot of forums, but I still don’t understand what the problem may be.
Be sure to call the Xcode preprocessor to handle OMP.
C++ flags should include:
-Xpreprocessor -fopenmp -lomp -I/usr/local/include
LDFLAGS should include:
-lomp
With cmake you may add them to your command:
cmake -DCMAKE_CXX_FLAGS="-Xpreprocessor -fopenmp -lomp -I/usr/local/include" -DCMAKE_EXE_LINKER_FLAGS="-lomp" ..
or you may add them to your CMakeLists.txt
After trying so many options from the following links
How to set up basic openMP project in CLion
How to set linker flags for OpenMP in CMake's try_compile function
.. and some more
I had the error The CMAKE_CXX_COMPILER: g++-6 is not a full path and was not found in the PATH.
So
i installed GNU gcc from brew instead of Clang (gcc#12 was installed)
brew install gcc
Changed the c++ and c compilers in Preferences > Build, Execution and Development > Toolchains in CLion to the installed compilers in 1
/usr/local/bin/gcc-12 // c
/usr/local/bin/g++-12 // c++
My CMakeList.txt file at this point looks like this:
cmake_minimum_required(VERSION 3.17)
project(test)
set(CMAKE_CXX_STANDARD 11)
add_executable(test main.cpp)
target_compile_options(test PRIVATE -Wall ${OpenMP_CXX_FLAGS})
target_link_libraries(test PRIVATE ${OpenMP_CXX_FLAGS})
and it worked for me.
Related
I am currently attempting to cross compile targeting Windows using cmake in Linux Subsystem for Windows Ubuntu. I am compiling form Linux because I want to be able to support multiple platforms.
I am unsure how to make this work, and have no preference of compiler.
See the following code and build output for my current attempt.
CMakeLists.txt file
cmake_minimum_required(VERSION 3.7)
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/win.toolchain.cmake)
project(environment.exe)
find_package(SDL2 REQUIRED)
include_directories(environment.exe ${SDL2_INCLUDE_DIRS})
# get executable src files
file(GLOB_RECURSE environment.exe_src ${CMAKE_CURRENT_SOURCE_DIR}/src/environment/*.cpp)
# add environment.exe executable
add_executable(environment.exe ${environment.exe_src})
target_link_libraries(environment.exe ${SDL2_LIBRARIES})
# set output dir
set_target_properties(
environment.exe
PROPERTIES
# ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin/suite/lib"
# LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin/suite/lib"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin/environment"
)
win.toolchain.cmake file
set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_SYSTEM_PROCESSOR x64)#i686
set(triple x64-pc-win32)
set(CMAKE_C_COMPILER clang)
set(CMAKE_C_COMPILER_TARGET ${triple})
set(CMAKE_CXX_COMPILER clang++)
set(CMAKE_CXX_COMPILER_TARGET ${triple})
BASH output
a#DESKTOP-DCHFQSJ:/mnt/e/d/User/Software Projects/windows-software-environment$ ./build.sh
Checking for make installation.
make is installed.
Checking for cmake installation.
cmake is installed.
Checking for mingw-w64 installation.
mingw-w64 is installed.
Checking for g++-mingw-w64 installation.
g++-mingw-w64 is installed.
Checking for libsdl2-dev installation.
libsdl2-dev is installed.
./build.sh: line 30: cd: ./build: No such file or directory
Running cmake on './build'
-- The C compiler identification is Clang 6.0.0
-- The CXX compiler identification is Clang 6.0.0
-- Check for working C compiler: /usr/bin/clang
-- Check for working C compiler: /usr/bin/clang -- broken
CMake Error at /usr/share/cmake-3.10/Modules/CMakeTestCCompiler.cmake:52 (message):
The C compiler
"/usr/bin/clang"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: /mnt/e/d/User/Software Projects/windows-software-environment/build/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/make" "cmTC_8a6e7/fast"
/usr/bin/make -f CMakeFiles/cmTC_8a6e7.dir/build.make CMakeFiles/cmTC_8a6e7.dir/build
make[1]: Entering directory '/mnt/e/d/User/Software Projects/windows-software-environment/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_8a6e7.dir/testCCompiler.c.obj
/usr/bin/clang --target=x64-pc-win32 -o CMakeFiles/cmTC_8a6e7.dir/testCCompiler.c.obj -c "/mnt/e/d/User/Software Projects/windows-software-environment/build/CMakeFiles/CMakeTmp/testCCompiler.c"
error: unknown target triple 'x64-pc-windows-msvc19.11.0', please use -triple or -arch
CMakeFiles/cmTC_8a6e7.dir/build.make:65: recipe for target 'CMakeFiles/cmTC_8a6e7.dir/testCCompiler.c.obj' failed
make[1]: *** [CMakeFiles/cmTC_8a6e7.dir/testCCompiler.c.obj] Error 1
make[1]: Leaving directory '/mnt/e/d/User/Software Projects/windows-software-environment/build/CMakeFiles/CMakeTmp'
Makefile:126: recipe for target 'cmTC_8a6e7/fast' failed
make: *** [cmTC_8a6e7/fast] Error 2
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:19 (project)
-- Configuring incomplete, errors occurred!
See also "/mnt/e/d/User/Software Projects/windows-software-environment/build/CMakeFiles/CMakeOutput.log".
See also "/mnt/e/d/User/Software Projects/windows-software-environment/build/CMakeFiles/CMakeError.log".
I'm trying to compile a project using my Mac (MacOsX High Sierra) and CMake version: 3.12.2
Clicking on "Generate" gives the following error:
CMake Error in CMakeLists.txt: No known features for CXX compiler "Clang" version 9.1.0.9020039.
My CMakeLists.txt is the following:
PROJECT(rightKidney_seg)
cmake_minimum_required(VERSION 2.4)
if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)
INCLUDE_REGULAR_EXPRESSION("^.*$")
FIND_PACKAGE(ITK REQUIRED)
IF(ITK_FOUND)
INCLUDE(${ITK_USE_FILE})
ENDIF(ITK_FOUND)
ADD_EXECUTABLE(rightKidney_seg rightKidney_seg.cxx)
TARGET_LINK_LIBRARIES(rightKidney_seg ${ITK_LIBRARIES})
If I do: which gcc the result is:
/usr/bin/gcc
If I do: cc --version the result is:
Apple LLVM version 9.1.0 (clang-902.0.39.2)
Target: x86_64-apple-darwin17.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
Can anyone help me in understanding why I cannot generate the project?
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.
I put
set(CMAKE_CXX_COMPILER "/usr/bin/clang.exe")
Run/Clean, Run/Build.
I get link errors like:
undefined reference to `std::ios_base::Init::~Init()'
: undefined reference to `__gxx_personality_v0'
Presumably there are other variables to change. Tried adding -lstdc++ to CMAKE_CXX_FLAGS, but no different.
Is there a CLion way as opposed to a CMake way, for example?
Thanks.
Specifying a compiler with CMake is a bit delicate. Although the method you are using, setting CMAKE_CXX_COMPILER in CMakeLists.txt works, it is the least-recommended way in the CMake FAQ.
CLion supports method 2 of the CMake FAQ: using -D within the cmake invocation. Setting the variables in CMakeLists.txt has no effect.
On Mac, go to Preferences
On Linux/Windows, go to File | Settings
then Build, Execution, Deployment | CMake | CMake options and enter the text:
-D CMAKE_C_COMPILER=/path/to/c_compiler
-D CMAKE_CXX_COMPILER=/path/to/c++_compiler
See the CLion FAQ for details.
Note also that when you change compilers, you will have to invalidate the CLion cmake cache and restart, see my answer on How to clear CMake cache in Clion?.
EDIT
After I wrote this answer, CLion added support for multiple build directories, as pointed out by #rubenvb in the comments. This is another path to investigate.
In fact the latest version of Clions 2018.2 running on windows 10 environment work with LLVM clang version 6 /6.0.1 or even 7.0 along with GCC mingw x64 win32 specific variant.
linker default is set to GCC not visual studio
I guess it should work on cygwin too with the same setup as the following also tested to work on a number of popular c++ IDE also.
x64 or 32 specific GCC mingw version tested to work on Clions 2018.2
\mingw-w64\x86_64-8.1.0-win32-seh-rt_v6-rev0 or mingw-w64\i686-8.1.0-win32-dwarf-rt_v6-rev0
CMake build setup as below
cmake_minimum_required(VERSION 3.10)
project(project_name )
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_C_COMPILER "c:/llvm/bin/clang.exe")
set(CMAKE_CXX_COMPILER "c:/llvm/bin/clang++.exe")
// target i686-pc-windows-gnu for 32bit
set(CL_COVERAGE_COMPILE_FLAGS "-v -target x86_64-pc-windows-gnu -Wall -Wextra -std=gnu++17")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CL_COVERAGE_COMPILE_FLAGS}" )
add_executable(project_name yourcpp.cpp)
Trying to install pdf2htmlEXon Ubuntu 14.04 but getting stuck with this error
Error: your compiler does not support C++0x, please update it.
Checked my version of both gcc & g++
gcc (Ubuntu 4.9.1-3ubuntu2~14.04.1) 4.9.1
g++ (Ubuntu 4.9.1-3ubuntu2~14.04.1) 4.9.1
Which should be ok for C++0x support. Also added a symbolic links for cc & c++. What am I missing here? Doesn't 4.9.1 support C++0x?
EDIT:
Error occurs when I'm trying to make the app using cmake .. here's what I can find in the CMakeLists.txt
# CYGWIN or GCC 4.5.x bug
if(CYGWIN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
endif()
>include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("${CMAKE_CXX_FLAGS}" CXX0X_SUPPORT)
if(NOT CXX0X_SUPPORT)
message(FATAL_ERROR "Error: your compiler does not support C++0x, please update it.")
endif()
Ok so it looks like ${CMAKE_CXX_FLAGS} was including
-stdlib=libc++
According to this post When is it necessary to use use the flag -stdlib=libstdc++? it's not necessary, so removed it seemed to solve the issue