在 Linux 上对 Windows 进行交叉编译时出现类型定义冲突

发布于 2025-01-16 18:47:25 字数 2686 浏览 4 评论 0原文

我正在尝试使用 MinGW-w64 交叉编译 Windows 应用程序。我的项目使用 GLFW,错误似乎来自它。

以下是编译器输出的一部分:

====================[ Build | opengl_tests | Windows Release ]==================
/home/sunnymonster/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/213.7172.20/bin/cmake/linux/bin/cmake --build /home/sunnymonster/dev/c++/opengl-tests/cmake-build/windows/release --target opengl_tests
[1/19] Building C object lib/glfw/src/CMakeFiles/glfw.dir/init.c.o
FAILED: lib/glfw/src/CMakeFiles/glfw.dir/init.c.o 
/usr/bin/x86_64-w64-mingw32-cc -DWINVER=0x0501 -D_GLFW_USE_CONFIG_H -I/home/sunnymonster/dev/c++/opengl-tests/lib/glfw/include -I/home/sunnymonster/dev/c++/opengl-tests/lib/glfw/src -I/home/sunnymonster/dev/c++/opengl-tests/cmake-build/windows/release/lib/glfw/src -I/usr/include -O3 -DNDEBUG -fPIC -Wall -std=gnu99 -Wdeclaration-after-statement -MD -MT lib/glfw/src/CMakeFiles/glfw.dir/init.c.o -MF lib/glfw/src/CMakeFiles/glfw.dir/init.c.o.d -o lib/glfw/src/CMakeFiles/glfw.dir/init.c.o -c /home/sunnymonster/dev/c++/opengl-tests/lib/glfw/src/init.c
In file included from /home/sunnymonster/dev/c++/opengl-tests/lib/glfw/src/../include/GLFW/glfw3.h:108,
                 from /home/sunnymonster/dev/c++/opengl-tests/lib/glfw/src/internal.h:49,
                 from /home/sunnymonster/dev/c++/opengl-tests/lib/glfw/src/init.c:30:
/usr/include/stdint.h:90:33: error: conflicting types for ‘uintptr_t’; have ‘long unsigned int’
   90 | typedef unsigned long int       uintptr_t;
      |                                 ^~~~~~~~~
In file included from /usr/x86_64-w64-mingw32/include/crtdefs.h:10,
                 from /usr/x86_64-w64-mingw32/include/stddef.h:7,
                 from /usr/lib/gcc/x86_64-w64-mingw32/11.2.0/include/stddef.h:1,
                 from /home/sunnymonster/dev/c++/opengl-tests/lib/glfw/src/../include/GLFW/glfw3.h:103,
                 from /home/sunnymonster/dev/c++/opengl-tests/lib/glfw/src/internal.h:49,
                 from /home/sunnymonster/dev/c++/opengl-tests/lib/glfw/src/init.c:30:
/usr/x86_64-w64-mingw32/include/corecrt.h:80:44: note: previous declaration of ‘uintptr_t’ with type ‘uintptr_t’ {aka ‘long long unsigned int’}
   80 | __MINGW_EXTENSION typedef unsigned __int64 uintptr_t;
      |                                            ^~~~~~~~~

我在网上做了一些研究,发现错误是由 MinGW-w64 引起的,包括本机 Linux 头文件。但是,我检查了我找到的来源之一中提到的 CPLUS_INCLUDE_PATH,它是空的。关于这个问题我找不到太多其他的信息。

我可以在这里尝试做什么来解决问题?提前致谢。

附加信息:

我使用 CLion 作为我的 IDE,它使用 CMake。为了使其能够针对 Windows 进行交叉编译,我更改了“工具链”设置中指定的 C 和 C++ 编译器,如下所示: 输入图片此处描述

I am trying to cross-compile an application for Windows using MinGW-w64. My project uses GLFW and the error seemed to have come from it.

Here is part of the compiler output:

====================[ Build | opengl_tests | Windows Release ]==================
/home/sunnymonster/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/213.7172.20/bin/cmake/linux/bin/cmake --build /home/sunnymonster/dev/c++/opengl-tests/cmake-build/windows/release --target opengl_tests
[1/19] Building C object lib/glfw/src/CMakeFiles/glfw.dir/init.c.o
FAILED: lib/glfw/src/CMakeFiles/glfw.dir/init.c.o 
/usr/bin/x86_64-w64-mingw32-cc -DWINVER=0x0501 -D_GLFW_USE_CONFIG_H -I/home/sunnymonster/dev/c++/opengl-tests/lib/glfw/include -I/home/sunnymonster/dev/c++/opengl-tests/lib/glfw/src -I/home/sunnymonster/dev/c++/opengl-tests/cmake-build/windows/release/lib/glfw/src -I/usr/include -O3 -DNDEBUG -fPIC -Wall -std=gnu99 -Wdeclaration-after-statement -MD -MT lib/glfw/src/CMakeFiles/glfw.dir/init.c.o -MF lib/glfw/src/CMakeFiles/glfw.dir/init.c.o.d -o lib/glfw/src/CMakeFiles/glfw.dir/init.c.o -c /home/sunnymonster/dev/c++/opengl-tests/lib/glfw/src/init.c
In file included from /home/sunnymonster/dev/c++/opengl-tests/lib/glfw/src/../include/GLFW/glfw3.h:108,
                 from /home/sunnymonster/dev/c++/opengl-tests/lib/glfw/src/internal.h:49,
                 from /home/sunnymonster/dev/c++/opengl-tests/lib/glfw/src/init.c:30:
/usr/include/stdint.h:90:33: error: conflicting types for ‘uintptr_t’; have ‘long unsigned int’
   90 | typedef unsigned long int       uintptr_t;
      |                                 ^~~~~~~~~
In file included from /usr/x86_64-w64-mingw32/include/crtdefs.h:10,
                 from /usr/x86_64-w64-mingw32/include/stddef.h:7,
                 from /usr/lib/gcc/x86_64-w64-mingw32/11.2.0/include/stddef.h:1,
                 from /home/sunnymonster/dev/c++/opengl-tests/lib/glfw/src/../include/GLFW/glfw3.h:103,
                 from /home/sunnymonster/dev/c++/opengl-tests/lib/glfw/src/internal.h:49,
                 from /home/sunnymonster/dev/c++/opengl-tests/lib/glfw/src/init.c:30:
/usr/x86_64-w64-mingw32/include/corecrt.h:80:44: note: previous declaration of ‘uintptr_t’ with type ‘uintptr_t’ {aka ‘long long unsigned int’}
   80 | __MINGW_EXTENSION typedef unsigned __int64 uintptr_t;
      |                                            ^~~~~~~~~

I have done some research online and found out that the error was caused by MinGW-w64 including the native Linux headers. However, I checked the CPLUS_INCLUDE_PATH mentioned in one of the sources I found, and it was empty. And there's not much else I can find about this problem.

What can I try and do here to solve the problem? Thanks in advance.

Additional information:

I'm using CLion as my IDE and it uses CMake. To make it cross-compile for Windows I changed the C and C++ compilers specified in the 'toolchains' settings like so:
enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

原谅过去的我 2025-01-23 18:47:25

我通过创建一个如下所示的 CMake 工具链文件解决了这个问题

# the name of the target operating system
set(CMAKE_SYSTEM_NAME Windows)

# adjust the default behavior of the FIND_XXX() commands:
# search programs in the host environment
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)

# search headers and libraries in the target environment
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

I've solved the problem by creating a CMake toolchain file that looks like this

# the name of the target operating system
set(CMAKE_SYSTEM_NAME Windows)

# adjust the default behavior of the FIND_XXX() commands:
# search programs in the host environment
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)

# search headers and libraries in the target environment
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文