2013-11-01 5 views
0

작은 C++ 코드를 빌드하려면 cmake으로 놀고 싶습니다.cmake 컴파일러가 존재하는지 확인하십시오.

나는 cmake . 내가 불쾌한 오류 메시지를 얻을 호출하면 아직 g++

을 (내가 버추얼의 OS에서 테스트하고있어)가 없습니다.

-- The C compiler identification is GNU 4.7.2 

**-- The CXX compiler identification is unknown** 

-- Check for working C compiler: /usr/bin/gcc 

-- Check for working C compiler: /usr/bin/gcc -- works 

-- Detecting C compiler ABI info 

-- Detecting C compiler ABI info - done 

**CMake Error: your CXX compiler: "CMAKE_CXX_COMPILER-NOTFOUND" was not found. Please set CMAKE_CXX_COMPILER to a valid compiler path or name. 

-- Configuring incomplete, errors occurred!** 

기본적으로 정상입니다. 그것은 오류가 발생했다고 말하지만 너무 많이 필요하다고 말합니다. 난 단지 "g ++ ist가 설치되어 있지 않다."라는 정확하고 간결한 메시지를 원합니다.

먼저 g++이 설치되어 있는지 확인한 다음 적절한 메시지를 제공 할 수 있습니까?

+0

당신은 우리가 –

+0

도움을 얻을 오류 그래서 당신이 오류를 수정하지 않으을 표시하고 프로젝트에서의 C++ 지원을 제거하지 마십시오, 당신은 오류 메시지를 변경하려면? 나는 그 오류 메시지가 아주 정확하다고 생각한다. (: –

답변

-1

GCC (GNU Compiler Collection) 프론트 엔드를 사용해야합니다. gcc-C++ 또는 비슷한 패키지를 설치해야합니다.

+0

그래,하지만이 단계에서는 내가 싫어. 목표는 먼저 그 존재를 확인하는 것이다. – Tengis

0

출력 결과는 CMake가 도움이되었다고 나타냅니다. 여러분의 취향에 너무 장황하다면 그것을 줄이는 가장 간단한 방법은 그것을 변수에 넣은 다음 그것을 검사하는 것입니다.

아래 샘플 CMake 스크립트를 detect_cxx_compiler.cmake으로 저장하고 cmake -P detect_cxx_compiler.cmake을 사용하여 스크립트를 호출 할 수 있습니다. 이 코드는 작은 크기 나 처리 효율이 아니라 CMake 초보자에게 도움이되는 방식으로 작성되었습니다.

cmake_minimum_required(VERSION 2.8.5 FATAL_ERROR) 
cmake_policy(VERSION 2.8.5) 

# This cmake script (when saved as detect_cxx_compiler.cmake) is invoked by: 
# 
#  cmake -P detect_cxx_compiler.cmake 
# 
# It is written for clarity, not brevity. 

# First make a new directory, so that we don't mess up the current one. 
execute_process(
    COMMAND ${CMAKE_COMMAND} -E make_directory detection_area 
    WORKING_DIRECTORY . 
) 

# Here, we generate a key file that CMake needs. 
execute_process(
    COMMAND ${CMAKE_COMMAND} -E touch CMakeLists.txt 
    WORKING_DIRECTORY detection_area 
) 

# Have CMake check the basic configuration. The output is 
# actually in the form that you posted in your question, but 
# instead of displaying it onscreen, we save it to a variable 
# so that we can select only parts of it to print later. 
execute_process(
    COMMAND ${CMAKE_COMMAND} --check-system-vars 
    OUTPUT_VARIABLE the_output 
    OUTPUT_STRIP_TRAILING_WHITESPACE 
    WORKING_DIRECTORY detection_area 
) 

# Eliminate the directory, including all of the files within it that 
# CMake created. 
execute_process(
    COMMAND ${CMAKE_COMMAND} -E remove_directory detection_area 
    WORKING_DIRECTORY . 
) 

# Here, you have the entire message captured as a variable. 
# Uncomment this next line to convince yourself of this. 
#message(STATUS "the_output = |${the_output}|.") 

# Here, we search the message to see if the C++ compiler was found or not, 
# and print an arbitrary message accordingly. 
string(FIND "${the_output}" "CMAKE_CXX_COMPILER-NOTFOUND" scan_result) 
#message(STATUS "scan_result = |${scan_result}|.") 
if(NOT(-1 EQUAL "${scan_result}")) 
    message(FATAL_ERROR "A C++ compiler was not detected.") 
endif() 

message(STATUS "A C++ compiler was detected.") 
관련 문제