Страницы

Поиск по вопросам

пятница, 15 февраля 2019 г.

CMake не видит компилятора

Поставил CMake (без CLang), добавил в переменную path путь к cmake-3.9.2/bin
cmake -version
работает.
Есть CMakeLists.txt файл
#cmake
cmake_minimum_required(VERSION 3.5)
project(concentration)
option(set_clang "set clang as default compiler" 0) option(set_gpp "set g++ as default compiler" 0) option(cros_compile "cros compile for win32" 0)
if(${UNIX}) message(STATUS "Unix system") elseif(${WIN32}) message(WARNING "Work is not guaranted") else() message(FATAL_ERROR "System not supported") endif()
if(set_gpp) set(CMAKE_CXX_COMPILER g++) endif() if(set_clang) set(CMAKE_CXX_COMPILER clang++) endif() if(cros_compile) set(PROJECT_NAME ${PROJECT_NAME}.exe) set(CMAKE_CXX_COMPILER i686-w64-mingw32-g++-posix) set(CMAKE_CXX_FLAGS "-static-libstdc++ -static-libgcc") endif()
message(STATUS "Project " ${PROJECT_NAME}) message(STATUS "cxx compiler " ${CMAKE_CXX_COMPILER})
add_definitions(-Wall -std=c++14)
include_directories(include)
set(MAIN_SRC sources/main.cpp) file(GLOB CONCENTRATION_SRC "sources/concentration/*.cpp")
if(cros_compile) find_package(PDCurses REQUIRED) else() find_package(Curses REQUIRED) endif()
include_directories(${CURSES_INCLUDE_DIR})
add_executable(${PROJECT_NAME} ${MAIN_SRC} ${CONCENTRATION_SRC})
target_link_libraries(${PROJECT_NAME} ${CURSES_LIBRARIES})
в общем когда запускаю командами
cmake cmake -Dset_gpp=1
CMake пишет:
-- The C compiler identification is unknown -- The CXX compiler identification is unknown CMake Error at CMakeLists.txt:5 (project): The CMAKE_C_COMPILER:
cl
is not a full path and was not found in the PATH.
To use the NMake generator with Visual C++, cmake must be run from a shell that can use the compiler cl from the command line. This environment is unable to invoke the cl compiler. To fix this problem, run cmake from the Visual Studio Command Prompt (vcvarsall.bat).
Tell CMake where to find the compiler by setting either the environment variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to the compiler, or to the compiler name if it is in the PATH.
CMake Error at CMakeLists.txt:5 (project): The CMAKE_CXX_COMPILER:
cl
is not a full path and was not found in the PATH.
To use the NMake generator with Visual C++, cmake must be run from a shell that can use the compiler cl from the command line. This environment is unable to invoke the cl compiler. To fix this problem, run cmake from the Visual Studio Command Prompt (vcvarsall.bat).
Tell CMake where to find the compiler by setting either the environment variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path to the compiler, or to the compiler name if it is in the PATH.
-- Configuring incomplete, errors occurred! See also "../CMakeFiles/CMakeOutput.log". See also "../CMakeFiles/CMakeError.log".
Путь к компилятору есть в path. g++ команда работает. Постоянно компилирую с командной строки. Пробовал в CmakeLists.txt указывать явный путь к g++. Все равно не помогает. Все пути к файлам - латиница.
В общем, нужна помощь!


Ответ

В Windows, судя по исходникам, CMake по дефолту (если генератор не указан явно) пробует найти (по записям в реестре) самую свежую версию Visual Studio, а если не находит, использует NMake.
Таким образом, если у вас установлена Студия (или просто остался мусор в реестре, в результате некорректного удаления студии или по другим, гораздо более серьезным причинам), то CMake будет делать проект под самую свежую из установленных Студий.
Чтобы явно указать нужный вам генератор, используйте ключик -G:
cmake -G "MinGW Makefiles"

Комментариев нет:

Отправить комментарий