CMake 报告损坏的 g++ 和缺少的 libiconv-2.dll

CMake reports broken g++ and missing libiconv-2.dll

当我按下 Configure 按钮时,CMake 出现一些奇怪的问题。

它一直报告我缺少libiconv-2.dll并且无法完成操作。但是,此库存在于 MinGW/bin 文件夹中。

我正在使用 CodeBlocks-MinGW Makefiles 和 CMake 版本 3.6.1 - 32 位版本(尽管 64 位版本也有同样的问题)。 一件有趣的事情是,在 consol 中它显示:

The CXX compiler identification is unknown

Check for working CXX compiler: C:/MinGW/bin/g++.exe

Check for working CXX compiler: C:/MinGW/bin/g++.exe -- broken

MinGW 已正确添加到系统路径,我能够检查版本 (GNU 4.8.1) 并使用命令行从命令行编译简单的 hello world:

g++ test.cpp -o test

在具有相同配置的另一台机器上测试相同的 CMakeLists 文件,但较旧的 CMake 版本 3.2.3 一切正常。在网上做了一些研究,我发现这个文件的问题并不新鲜,所以我怀疑这是版本问题。

有人知道可以做些什么吗?

编辑 1 这是CMakeError.log

的内容

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

The output was: 1

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

The output was: 1

Checking whether the CXX compiler is IAR using "" did not match "IAR .+ Compiler": g++.exe: fatal error: no input files compilation terminated. Determining if the CXX compiler works failed with the following output: Change Dir: C:/Users/testuser/Desktop/build/CMakeFiles/CMakeTmp

Run Build Command:"C:/MinGW/bin/mingw32-make.exe" "cmTC_c9a03/fast" C:/MinGW/bin/mingw32-make.exe -f CMakeFiles\cmTC_c9a03.dir\build.make CMakeFiles/cmTC_c9a03.dir/build

mingw32-make.exe1: Entering directory 'C:/Users/testuser/Desktop/build/CMakeFiles/CMakeTmp'

Building CXX object CMakeFiles/cmTC_c9a03.dir/testCXXCompiler.cxx.obj

C:\MinGW\bin\g++.exe -o CMakeFiles\cmTC_c9a03.dir\testCXXCompiler.cxx.obj -c C:\Users\testuser\Desktop\build\CMakeFiles\CMakeTmp\testCXXCompiler.cxx

CMakeFiles\cmTC_c9a03.dir\build.make:64: recipe for target 'CMakeFiles/cmTC_c9a03.dir/testCXXCompiler.cxx.obj' failed

mingw32-make.exe1: *** [CMakeFiles/cmTC_c9a03.dir/testCXXCompiler.cxx.obj] Error 1

mingw32-make.exe1: Leaving directory 'C:/Users/testuser/Desktop/build/CMakeFiles/CMakeTmp'

Makefile:125: recipe for target 'cmTC_c9a03/fast' failed

mingw32-make.exe: *** [cmTC_c9a03/fast] Error 2

我已经用 g++ 手动编译了文件 testCXXCompiler.cpp 并且成功了。编译时没有错误。

编辑 2

我创建了 SSCCE 来测试问题是否出在某些依赖项或其他一些与代码相关的问题上。但是测试这个文件:

test.cpp

#include <iostream>

int main()
{
    std::cout << "Test" << std::endl;
    return 0;
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.6)
project(Test)
add_executable(Test test.cpp)

我仍然有缺少库的问题。控制台输出略有变化,现在是:

The C compiler identification is unknown

The CXX compiler identification is unknown

Check for working C compiler: C:/MinGW/bin/gcc.exe

Check for working C compiler: C:/MinGW/bin/gcc.exe -- broken

我想我已经找到答案了。至少它对我有用。

显然我需要 运行 另一台机器上的 CMake 作为 管理员。这样我假设它可以正确访问 GCC 文件。但是,我不完全确定为什么在另一台机器上不需要它并且工作得很好。

您可能需要重新安装库

mingw-get install --reinstall mingw32-libiconv-dll

我遇到了一个非常相似的问题,并以这种方式解决了。