安装了 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。
因此,如果您安装了 Studio(或者只是在注册表中留下了一些垃圾,由于 Studio 的错误删除或其他更严重的原因),那么 CMake 将使项目安装在最新的 Studio 下。
要明确指定您需要的生成器,请使用 -G 开关: