CXX 编译器标识未知:xcode

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33998853/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 08:16:09  来源:igfitidea点击:

The CXX compiler identification is unknown: xcode

c++xcodecmake

提问by Whizzil

I am trying to install an external library into my C++ project using Cmake. I want the Xcodeproject to be produced with that library. In my terminal i run the following from the build directory:

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

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:

我正在使用 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

Edit: CMakeLists.txt file

编辑: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()

Also CMakeEdit.log:

还有 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).

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

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:

完成此操作后,当我运行时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)

EDIT 2Looks like the SDK specified by the OS is wrong.

编辑 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)

采纳答案by l'L'l

The error you have with the SDK can usually be solved by clearing the CMake build cache and adding the following to your CMakeLists.txtbefore project():

您在 SDK 中遇到的错误通常可以通过清除 CMake 构建缓存并将以下内容添加到CMakeLists.txt之前的 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.

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

? https://github.com/Homebrew/homebrew/issues/23074

? https://github.com/Homebrew/homebrew/issues/23074

回答by 4dan

I had the same problem, but I solved it with:

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

sudo xcode-select --reset

Before doing the above, xcode-select -preported the path was /Library/Developer/CommandLineTools.

在执行上述操作之前,xcode-select -p报告路径为/Library/Developer/CommandLineTools.

After the reset, the path was /Applications/Xcode.app/Contents/Developer.

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

回答by Arwed Mett

I had the same output and could solve it by agreeing to the apple license.

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

sudo xcodebuild -license accept

回答by Rotsiser Mho

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.

我通过打开 Xcode 应用程序,转到首选项 -> 位置,然后从命令行工具的下拉列表中选择 Xcode 安装来解决它。它最初是空白的。

回答by Fileland

I solved a similar problem by

我解决了一个类似的问题

sudo xcodebuild -license

After agreeing the license, C compiler and CXX compiler can be identified.

同意许可后,可以识别C编译器和CXX编译器。

================================

================================

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!