Mac Cmake error: No known features for CXX compiler - c++

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?

Related

CMake cannot find lboost_* in mingw

​Installed:
Windows 10 64 bit
cmake version 3.21.3
gcc (Rev5, Built by MSYS2 project) 10.3.0 (MinGW 4.8.X and The latest version)
While executing the make command on the CMakeLists.txt file, I encountered the error can not find lboost _filesystem, followed by the link https://www.boost.org/users/history/version_1_77_0.html, boost for my system I created, however this does not work for me.
CMakeLists.txt:
cmake_minimum_required(VERSION 3.7)
project(obj_loader)
execute_process(COMMAND python -c "import tensorflow; print(tensorflow.sysconfig.get_include())" OUTPUT_VARIABLE Tensorflow_default_INCLUDE_DIRS)
set(Tensorflow_INCLUDE_DIRS "${Tensorflow_default_INCLUDE_DIRS}" CACHE PATH "Tensorflow include path")
include_directories(${Tensorflow_INCLUDE_DIRS})
set(CMAKE_CXX_STANDARD 11)
set(SOURCE_FILES obj_loader.cpp)
add_library(obj_loader SHARED ${SOURCE_FILES})
target_link_libraries(obj_loader boost_filesystem)
enter image description here

Set the OpenMP project MacOS Mojave in CLion

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.

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.

Mixing C++ and Fortran

Is there a way to use the Clang compiler while mixing C++ and Fortran?
Until now I use cmake with
project(mixing CXX Fortran)
but this triggers the use of g++.
-- The CXX compiler identification is GNU 6.2.0
CMakeLists.txt of my project with Fortran mixing:
cmake_minimum_required(VERSION 3.7.0)
project(mixing CXX Fortran)
# SET UP ROOT https://root.cern.ch/how/integrate-root-my-project-cmake
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} /opt/local/libexec/root6/etc/root/cmake)
find_package(ROOT REQUIRED COMPONENTS MATH MINUIT2)
include(${ROOT_USE_FILE})
include_directories(Experiment Theory ${ROOT_INCLUDE_DIRS})
add_executable(mixing main.cpp)
target_link_libraries(mixing ${ROOT_LIBRARIES})
Not working, because g++ cannot use the needed Clang flag -stdlib=libc++ of the ROOT library.
You can always override c/c++ compiler by changing CMAKE_<LANG>_COMPILER, where <LANG> in your case is C or CXX.
You can set your CC and CXX environment variables to override defaults for CMAKE_C_COMPILER / CMAKE_CXX_COMPILER:
CC=clang CXX=clang++ cmake
You can set these on command line when invoking cmake:
cmake -D CMAKE_C_COMPILER=clang -D CMAKE_CXX_COMPILER=clang++
You can also set these directly in your cmake file:
set(CMAKE_C_COMPILER clang)
set(CMAKE_CXX_COMPILER clang++)
make sure however that you do that at the very top of your cmake file before any project/enable_language directive is used.

The CXX compiler identification is unknown: xcode

I am trying to install an external library into my C++ project using Cmake. I want the Xcode project to be produced with that library. In my terminal i run the following from the build directory:
cmake -G Xcode ..
and that gives me the following errors:
-- The CXX compiler identification is unknown
-- The C compiler identification is unknown
CMake Error at CMakeLists.txt:6 (project):
No CMAKE_CXX_COMPILER could be found.
CMake Error at CMakeLists.txt:6 (project):
No CMAKE_C_COMPILER could be found.
I am using g++ compiler:
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.0.0 (clang-700.1.76)
Target: x86_64-apple-darwin14.5.0
Thread model: posix
Edit: CMakeLists.txt file
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/VERSION" PROJECT_VERSION_FULL)
string(REGEX REPLACE "[\n\r]" "" PROJECT_VERSION_FULL "${PROJECT_VERSION_FULL}")
string(REGEX REPLACE "^([0-9]+)\\.[0-9]+\\.[0-9]+$" "\\1" PROJECT_VERSION_MAJOR "${PROJECT_VERSION_FULL}")
string(REGEX REPLACE "^[0-9]+\\.([0-9]+)\\.[0-9]+$" "\\1" PROJECT_VERSION_MINOR "${PROJECT_VERSION_FULL}")
string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+)$" "\\1" PROJECT_VERSION_PATCH "${PROJECT_VERSION_FULL}")
set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}")
math(EXPR LIBRARY_VERSION_MAJOR "${PROJECT_VERSION_MAJOR}")
set(LIBRARY_VERSION_MINOR "${PROJECT_VERSION_MINOR}")
set(LIBRARY_VERSION_PATCH "${PROJECT_VERSION_PATCH}")
set(LIBRARY_VERSION "${LIBRARY_VERSION_MAJOR}.${LIBRARY_VERSION_MINOR}")
set(LIBRARY_VERSION_FULL "${LIBRARY_VERSION}.${LIBRARY_VERSION_PATCH}")
option(CODE_COVERAGE "Set ON to add code coverage compile options" OFF)
option(GENERATE_DOC "Set ON to genrate doxygen API reference in build/doc directory" OFF)
# C++11 compiler Check
if(NOT CMAKE_CXX_COMPILER_VERSION) # work around for cmake versions smaller than 2.8.10
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE CMAKE_CXX_COMPILER_VERSION)
endif()
if(CMAKE_CXX_COMPILER MATCHES ".*clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_COMPILER_IS_CLANGXX 1)
endif()
if( (CMAKE_COMPILER_IS_GNUCXX AND ${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 4.7) OR
(CMAKE_COMPILER_IS_CLANGXX AND ${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 3.2))
message(FATAL_ERROR "Your C++ compiler does not support C++11. Please install g++ 4.7 (or greater) or clang 3.2 (or greater)")
else()
message(STATUS "Compiler is recent enough to support C++11.")
endif()
if( CMAKE_COMPILER_IS_GNUCXX )
append_cxx_compiler_flags("-std=c++11 -Wall -Wextra -DNDEBUG" "GCC" CMAKE_CXX_FLAGS)
append_cxx_compiler_flags("-O3 -ffast-math -funroll-loops" "GCC" CMAKE_CXX_OPT_FLAGS)
if ( CODE_COVERAGE )
append_cxx_compiler_flags("-g -fprofile-arcs -ftest-coverage -lgcov" "GCC" CMAKE_CXX_FLAGS)
endif()
else()
if(MSVC)
append_cxx_compiler_flags("/EHsc" "MSVC" CMAKE_CXX_FLAGS)
append_cxx_compiler_flags("/Od" "MSVC" CMAKE_CXX_FLAGS_DEBUG)
append_cxx_compiler_flags("/Ox" "MSVC" CMAKE_CXX_FLAGS_RELEASE)
set(vars CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
foreach(var ${vars})
string(REPLACE "/MD" "-MT" ${var} "${${var}}")
endforeach(var)
add_definitions("/DMSVC_COMPILER")
else()
append_cxx_compiler_flags("-std=c++11 -DNDEBUG" "CLANG" CMAKE_CXX_FLAGS)
append_cxx_compiler_flags("-stdlib=libc++" "CLANG" CMAKE_CXX_FLAGS)
append_cxx_compiler_flags("-O3 -ffast-math -funroll-loops" "CLANG" CMAKE_CXX_OPT_FLAGS)
endif()
endif()
Also CMakeEdit.log:
Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed.
Compiler:
Build flags:
Id flags:
The output was:
1
xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance
Compiling the C compiler identification source file "CMakeCCompilerId.c" failed.
Compiler:
Build flags:
Id flags:
The output was:
1
xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance
EDIT:
This problem happens when xcode-select developer directory was pointing to /Library/Developer/CommandLineTools, when a full regular XCode was required (happens when CLT are installed after XCode).
I have found the solution to be this:
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
After this being done, when I run cmake -G Xcode .. I get other errors:
-- The CXX compiler identification is AppleClang 7.0.0.7000176
-- The C compiler identification is AppleClang 7.0.0.7000176
CMake Error at /usr/local/Cellar/cmake/3.4.0/share/cmake/Modules/Platform/Darwin.cmake:76 (message):
CMAKE_OSX_DEPLOYMENT_TARGET is '10.10' but CMAKE_OSX_SYSROOT:
""
is not set to a MacOSX SDK with a recognized version. Either set
CMAKE_OSX_SYSROOT to a valid SDK or set CMAKE_OSX_DEPLOYMENT_TARGET to
empty.
Call Stack (most recent call first):
/usr/local/Cellar/cmake/3.4.0/share/cmake/Modules/CMakeSystemSpecificInformation.cmake:36 (include)
CMakeLists.txt:6 (project)
EDIT 2
Looks like the SDK specified by the OS is wrong.
CMAKE_OSX_DEPLOYMENT_TARGET is '10.10' but the matching SDK does not exist
at:
"/Applications/DEV/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk"
Instead using SDK:
"/Applications/DEV/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk".
Call Stack (most recent call first):
/usr/local/Cellar/cmake/3.4.0/share/cmake/Modules/CMakeSystemSpecificInitialize.cmake:18 (include)
CMakeLists.txt:6 (project)
-- The CXX compiler identification is AppleClang 7.0.0.7000176
-- The C compiler identification is AppleClang 7.0.0.7000176
CMake Error at /usr/local/Cellar/cmake/3.4.0/share/cmake/Modules/Platform/Darwin.cmake:76 (message):
CMAKE_OSX_DEPLOYMENT_TARGET is '10.10' but CMAKE_OSX_SYSROOT:
""
is not set to a MacOSX SDK with a recognized version. Either set
CMAKE_OSX_SYSROOT to a valid SDK or set CMAKE_OSX_DEPLOYMENT_TARGET to
empty.
Call Stack (most recent call first):
/usr/local/Cellar/cmake/3.4.0/share/cmake/Modules/CMakeSystemSpecificInformation.cmake:36 (include)
CMakeLists.txt:6 (project)
I had the same problem, but I solved it with:
sudo xcode-select --reset
Before doing the above, xcode-select -p reported the path was /Library/Developer/CommandLineTools.
After the reset, the path was /Applications/Xcode.app/Contents/Developer.
I had the same output and could solve it by agreeing to the apple license.
sudo xcodebuild -license accept
The error you have with the SDK can usually be solved by clearing the CMake build cache and adding the following to your CMakeLists.txt before project():
SET(MACOSX_DEPLOYMENT_TARGET ${DARWIN_MAJOR_SDK_VERSION}.${DARWIN_MINOR_SDK_VERSION})
SET(CMAKE_CXX_FLAGS "--sysroot ${CMAKE_OSX_SYSROOT} ${CMAKE_CXX_FLAGS}")
MESSAGE("Setting MACOSX_DEPLOYMENT_TARGET to '${MACOSX_DEPLOYMENT_TARGET}'.")
If you find that doesn't solve the issue then you should check the version of Xcode is current and has the SDK installed you are specifying. Generally Homebrew and Macports CMake both should have the latest stable build of Xcode installed.
↳ https://github.com/Homebrew/homebrew/issues/23074
I had the same issue and as mentioned in one of the comments it appears to be due to the fact that I installed the command-line tools first.
I solved it by opening the Xcode app, going to Preferences -> Locations, and selecting the Xcode installation from the dropdown for Command Line Tools. It was initially blank.
I solved a similar problem by
sudo xcodebuild -license
After agreeing the license, C compiler and CXX compiler can be identified.
================================
As a reference, my error message is:
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- broken
CMake Error at /usr/local/Cellar/cmake/3.13.3/share/cmake/Modules/CMakeTestCCompiler.cmake:52 (message):
The C compiler "/usr/bin/cc" is not able to compile a simple test program.
It fails with the following output:
Change Dir: /Users/MyName/pyscf/pyscf/lib/build/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/make" "cmTC_114dd/fast"
Agreeing to the Xcode/iOS license requires admin privileges, please run “sudo xcodebuild -license” and then retry this command.
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:16 (project)
-- Configuring incomplete, errors occurred!
After upgrading to the latest version of CMake, it worked again.
cmake 3.25.0
AppleClang 14.0.0.14000029