【问题标题】:CMake build with gcc/g++ fails on Windows在 Windows 上使用 gcc/g++ 构建 CMake 失败
【发布时间】:2019-05-30 07:06:22
【问题描述】:

我已经在 Windows 7 Enterprise 和 10 上安装了 CMake 3.14.4(来自 cmake-3.14.4-win64-x64.msi)和 GCC 5.1.0(来自 tdm64-gcc-5.1.0-2.exe)主页(64 位)。

我正在尝试从 cpp/hpp 源文件 github sources. 构建 .LIL CMakeLists.txt 指的是 COTS 安装中的包含目录。包含目录中的头文件有这个 if-else 并且 CMake 构建总是会因为落在下面的最后一个 else 块中而出错:

# if defined(_M_AMD64)
#  include <wchar.h>
#  if BIP_CXX11_SUPPORT
typedef char16_t CciChar;
#  else
typedef wchar_t CciChar;
#  endif
typedef __int64 CciInt;
typedef unsigned __int64 CciCount;
#  define __CCI_WINDOWS__
# else
#  error The C plugin interface for IBM Integration Bus is only available 
for 64-bit Windows x86-64 systems
#endif

步骤:

1. c:\iib-swm\build>cmake -DIIB_INSTALL_DIR=C:\Progra~1\IBM\IIB\10.0.0.12 
-G "MinGW Makefiles" ../source
-- The CXX compiler identification is GNU 5.1.0
-- Check for working CXX compiler: C:/software/C++Tools/tdm- 
gcc/bin/g++.exe
-- Check for working CXX compiler: C:/software/C++Tools/tdm- 
gcc/bin/g++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: C:/iib-swm/build

这是CMakeSystem.cmake这一步之后的内容:

set(CMAKE_HOST_SYSTEM "Windows-6.1.7601")
set(CMAKE_HOST_SYSTEM_NAME "Windows")
set(CMAKE_HOST_SYSTEM_VERSION "6.1.7601")
set(CMAKE_HOST_SYSTEM_PROCESSOR "AMD64")



set(CMAKE_SYSTEM "Windows-6.1.7601")
set(CMAKE_SYSTEM_NAME "Windows")
set(CMAKE_SYSTEM_VERSION "6.1.7601")
set(CMAKE_SYSTEM_PROCESSOR "AMD64")

set(CMAKE_CROSSCOMPILING "FALSE")

set(CMAKE_SYSTEM_LOADED 1)

2. c:\iib-swm\build>cmake --build .

   -- Configuring done
   -- Generating done
   -- Build files have been written to: C:/iib-swm/build
   [ 33%] Building CXX object 
   CMakeFiles/statsdsw.dir/StatsdStatsWriter.cpp.obj
   In file included from 
   C:/Progra~1/IBM/IIB/10.0.0.12/server/include/plugin/BipCci.h:14:0,
             from 
   C:/Progra~1/IBM/IIB/10.0.0.12/server/include/plugin/BipCsi.h:14,
             from C:\iib-swm\source\StatsdStatsWriter.hpp:13,
             from C:\iib-swm\source\StatsdStatsWriter.cpp:10:
   C:/Progra~1/IBM/IIB/10.0.0.12/server/include/plugin/BipCos.h:170:4: 
   error: #error The C plugin inter
   face for IBM Integration Bus is only available for 64-bit Windows x86- 
   64 systems
   #  error The C plugin interface for IBM Integration Bus is only 
   available for 64-bit Windows x86-64
   systems
      ^
   CMakeFiles\statsdsw.dir\build.make:62: recipe for target 
   'CMakeFiles/statsdsw.dir/StatsdStatsWriter.
   cpp.obj' failed
   mingw32-make.exe[2]: *** 
   [CMakeFiles/statsdsw.dir/StatsdStatsWriter.cpp.obj] Error 3
   CMakeFiles\Makefile2:71: recipe for target 
   'CMakeFiles/statsdsw.dir/all' failed
   mingw32-make.exe[1]: *** [CMakeFiles/statsdsw.dir/all] Error 130
   Makefile:82: recipe for target 'all' failed
   mingw32-make.exe: *** [all] Error 130

我只是无法理解,即使 CMake 将系统处理器识别为 AMD64,它也不会在包含 .h 文件中转换为 _M_AMD64?我在网上搜索了 CMake 和相关资源。尝试以管理员身份运行 CMake,缩短了将 git 项目克隆到的路径,但没有运气。

PS:我唯一一次接触 cpp 是 15 年前在 Uni

【问题讨论】:

    标签: windows gcc cmake


    【解决方案1】:

    _M_AMD64 似乎特定于 Visual Studio 编译器。这个问题令人困惑,因为它表明 CMake 正在进行预处理。它没有。您正在使用gccgcc 似乎没有实现 Visual Studio 特定的预处理器宏。

    您要么必须更改代码以使用 gcc,要么使用像 target_compile_definitions 这样的 CMake 命令自己定义缺少的宏。

    请注意,README 文件表示使用 Visual Studio 2015 在 Windows 上构建。

    【讨论】:

    • 所有好的建议弗雷德。关于你的第一段,我知道 CMake 会为构建阶段设置处理器/位数信息,否则,按照我得到的步骤,编译器如何知道目标系统的这些属性?
    • @PKay 您可以使用make VERBOSE=1 查看 CMake 选择的命令行选项。对我来说,CMake 根本没有设置处理器。 CMake 只是为它创建的目标使用编译器默认值。我正在使用的gcc 版本是为'-mtune=generic' '-march=i586' 生成代码而构建的。当然,如果你想要像 -march=native 这样特定的东西,你可以覆盖这些,它会为本地目标编译一些东西,但可能不会在其他目标上运行。
    • 我使用 Cmake 和 VS 2015 在 Win10(我的笔记本电脑)上构建了 dll,指定 CMake -G "Visual Studio 14 2015 Win64"。重启后 COTS 产品在 Win10 上识别(注册)。但是,该 dll 无法在 Win 7 Enterprise SP1 (My Dev WS) 上注册。 Windows 声明 VS2015 在使用 Win 10 SDK 构建时会创建对 Universal CRT 的依赖项(如我的情况)。 UCRT 在 Win 7 SP1 上不可用。此外,我们的环境有 Win 2008 Server R2 SP1。因此,即使使用正确的处理器和位数执行构建,我也必须考虑不同风格的 Win OS。
    猜你喜欢
    • 2021-11-27
    • 1970-01-01
    • 2013-02-25
    • 2018-11-18
    • 2014-08-26
    • 2020-02-06
    • 1970-01-01
    • 1970-01-01
    • 2016-07-26
    相关资源
    最近更新 更多