2013-11-01 136 views
0

我試圖與cmake一起構建一個小型的C++代碼。cmake檢查是否存在編譯器

我沒有尚未g++ (我測試在VirtualBox的操作系統)

當我打電話cmake . 我得到的討厭的錯誤信息。

-- 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 not installed,please install it please」。

有沒有辦法先檢查g++是否已安裝,然後給出適當的信息?

+0

請出示你,所以我們可以幫助 –

+0

的錯誤,所以你不希望修復這個錯誤,並且不希望從項目中刪除C++的支持,你只是想更改錯誤信息?我認爲這個錯誤信息是相當準確的(: – 2013-11-02 05:21:30

回答

-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.")