cMake + MinGW on windows 10

it2022-05-05  122

using cmake with MinGW g++ on win10

FILE DIRECTORY

+ helloworld - CMakeFiles.txt - helloworld.cpp: + build

FILE

CMakeFIles.txt

project(helloWorld) add_executable(hello helloworld.cpp)

helloworld.cpp

\* * helloworld.cpp *\ #inlcude "iostream.cpp" using namespace std; int main() { cout<<"helloWorld.cpp"<<endl; return 0; };

PROBLEM

直接使用 cmake 会有错误信息:

$ cmake ../ -- Building for: NMake Makefiles -- The C compiler identification is unknown -- The CXX compiler identification is unknown CMake Error at CMakeLists.txt:2 (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:2 (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 "C:/Users/Ben/Documents/workspace/helloWorld/build/CMakeFiles/CMakeOutput.log". See also "C:/Users/Ben/Documents/workspace/helloWorld/build/CMakeFiles/CMakeError.log".

SOLVING

应用 -G"Unix Makefiles" 可以解决:

$ cmake -G"Unix Makefiles" ../

最新回复(0)