CXX编译器标识未知:xcode

Whi*_*zil 12 c++ xcode cmake

我正在尝试使用外部库安装到我的C++项目中Cmake.我希望Xcode用该库生成项目.在我的终端中,我从构建目录运行以下命令:

cmake -G Xcode ..
Run Code Online (Sandbox Code Playgroud)

这给了我以下错误:

-- 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.
Run Code Online (Sandbox Code Playgroud)

我正在使用g ++编译器:

 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
Run Code Online (Sandbox Code Playgroud)

编辑:CMakeLists.txt文件

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()
Run Code Online (Sandbox Code Playgroud)

还有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
Run Code Online (Sandbox Code Playgroud)

编辑:

当xcode-select开发人员目录指向/ Library/Developer/CommandLineTools时,当需要完整的常规XCode时(在XCode之后安装CLT时)会发生此问题.

我找到了解决方案:

sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
Run Code Online (Sandbox Code Playgroud)

完成此操作后,当我运行时,cmake -G Xcode ..我得到其他错误:

-- 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)
Run Code Online (Sandbox Code Playgroud)

编辑2 看起来操作系统指定的SDK是错误的.

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)
Run Code Online (Sandbox Code Playgroud)

4da*_*dan 13

我有同样的问题,但我解决了它:

sudo xcode-select --reset
Run Code Online (Sandbox Code Playgroud)

在做上述事情之前,xcode-select -p报道了路径/Library/Developer/CommandLineTools.

重置后,路径是/Applications/Xcode.app/Contents/Developer.


Arw*_*ett 6

我有相同的输出,可以通过同意Apple许可来解决。

sudo xcodebuild -license accept
Run Code Online (Sandbox Code Playgroud)

  • 这给了我`xcode-select:错误:工具'xcodebuild'需要Xcode,但活动开发人员目录'/Library/Developer/CommandLineTools'是命令行工具实例`。编辑:直到我按照 4dan 的答案解决了这个问题。 (2认同)

l'L*_*L'l 3

SDK 出现的错误通常可以通过清除 CMake 构建缓存并将以下内容添加到CMakeLists.txtbefore project() 来解决:

\n\n
SET(MACOSX_DEPLOYMENT_TARGET ${DARWIN_MAJOR_SDK_VERSION}.${DARWIN_MINOR_SDK_VERSION})\nSET(CMAKE_CXX_FLAGS "--sysroot ${CMAKE_OSX_SYSROOT} ${CMAKE_CXX_FLAGS}")\nMESSAGE("Setting MACOSX_DEPLOYMENT_TARGET to \'${MACOSX_DEPLOYMENT_TARGET}\'.")\n
Run Code Online (Sandbox Code Playgroud)\n\n

如果您发现这不能解决问题,那么您应该检查 Xcode 的版本是否为最新版本以及是否安装了您指定的 SDK。一般来说,Homebrew 和 Macports CMake 都应该安装最新的稳定版本的 Xcode。

\n\n

\xe2\x86\xb3 https://github.com/Homebrew/homebrew/issues/23074

\n