使用CMake的Assimp编译报错:GCC无法编译测试程序

Assimp Compilation Error Using CMake: GCC Cannot Compile Test Program

我正在尝试使用 CMake 为 Windows 10 编译 Assimp 5.0.1。我通过 MinGW 使用的 C/C++ 编译器是 GCC 和 G++。如果我正确地理解了问题,那么 MakeFile 的空白在某处存在问题。 /CMakeTmp/ 目录是空的,我确信答案就在我面前的某处:

控制台输出:

-- The C compiler identification is GNU 9.2.0
-- The CXX compiler identification is GNU 9.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: C:/MinGW/bin/gcc.exe
-- Check for working C compiler: C:/MinGW/bin/gcc.exe - broken
CMake Error at C:/Program Files (x86)/CMake/share/cmake-3.20/Modules/CMakeTestCCompiler.cmake:66 (message):
  The C compiler

    "C:/MinGW/bin/gcc.exe"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: Q:/programming/westy/src/lib/assimp-5.0.1/build/CMakeFiles/CMakeTmp

    Run Build Command(s):make -f Makefile /nologo cmTC_a4ec5\fast && Makefile:37: *** missing separator.  Stop.



  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:54 (PROJECT)


-- Configuring incomplete, errors occurred!
See also "Q:/programming/westy/src/lib/assimp-5.0.1/build/CMakeFiles/CMakeOutput.log".
See also "Q:/programming/westy/src/lib/assimp-5.0.1/build/CMakeFiles/CMakeError.log".

CMakeError.log:

Detecting C compiler ABI info failed to compile with the following output:
Change Dir: Q:/programming/westy/src/lib/assimp-5.0.1/build/CMakeFiles/CMakeTmp

Run Build Command(s):make -f Makefile /nologo cmTC_165dc\fast && Makefile:37: *** missing separator.  Stop.

CMakeOutput.log:

Compiling the C compiler identification source file "CMakeCCompilerId.c" succeeded.
Compiler: C:/MinGW/bin/gcc.exe 
Build flags: 
Id flags:  

The output was:
0


Compilation of the C compiler identification source "CMakeCCompilerId.c" produced "a.exe"

The C compiler identification is GNU, found in "Q:/programming/westy/src/lib/assimp-5.0.1/build/CMakeFiles/3.20.2/CompilerIdC/a.exe"

Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" succeeded.
Compiler: C:/MinGW/bin/g++.exe 
Build flags: 
Id flags:  

The output was:
0


Compilation of the CXX compiler identification source "CMakeCXXCompilerId.cpp" produced "a.exe"

The CXX compiler identification is GNU, found in "Q:/programming/westy/src/lib/assimp-5.0.1/build/CMakeFiles/3.20.2/CompilerIdCXX/a.exe"

您为 cmake 使用了哪个 -G 选项? make/nologo 参数似乎不正确,看起来像 Microsoft/MSVC 参数。如果你没有指定 -G 那么 CMake 默认为 -G"NMake Makefiles" on Windows.

如果您使用 MSYS 的 make.

,请确保为 mingw32-make-G"MSYS Makefiles" 使用 cmake 标志 -G"MinGW Makefiles"

但要避免所有这些问题并提高速度,-GNinja 是最好的解决方案,前提是您有 Ninja 可用(参见 https://ninja-build.org/)。

最后,您仍在使用 MinGW GCC 9.2.0。有较新的版本可用,请参阅 http://winlibs.com/ 以了解独立版本也包含较新的版本 mingw32-make