在 Linux 上对 Windows 进行交叉编译时出现类型定义冲突
我正在尝试使用 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:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过创建一个如下所示的 CMake 工具链文件解决了这个问题
I've solved the problem by creating a CMake toolchain file that looks like this