简体   繁体   English

在 linux 上交叉编译 windows 时出现类型定义冲突

[英]Conflicting typedefs when cross compiling for windows on linux

I am trying to cross-compile an application for Windows using MinGW-w64.我正在尝试使用 MinGW-w64 交叉编译 Windows 的应用程序。 My project uses GLFW and the error seemed to have come from it.我的项目使用 GLFW,错误似乎来自它。

Here is part of the compiler output:这是编译器 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.我在网上做了一些研究,发现错误是由 MinGW-w64 引起的,包括本机 Linux 标头。 However, I checked the CPLUS_INCLUDE_PATH mentioned in one of the sources I found, and it was empty.但是,我检查了我发现的其中一个来源中提到的 CPLUS_INCLUDE_PATH,它是空的。 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:我将 CLion 用作我的 IDE,它使用 CMake。为了使其针对 Windows 进行交叉编译,我更改了“工具链”设置中指定的 C 和 C++ 编译器,如下所示: 在此处输入图像描述

I've solved the problem by creating a CMake toolchain file that looks like this我通过创建一个如下所示的 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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Linux上与mingw-w64交叉编译时的声明冲突 - Conflicting declaration when cross compiling with mingw-w64 on Linux 使用 Clang / OLLVM 在 Linux 上交叉编译 helloworld Windows 可执行文件时出现问题 - Issues when cross compiling helloworld Windows executable on Linux with Clang / OLLVM 在Linux上交叉编译Windows应用程序时如何链接到Winsock? - How to link to Winsock when cross-compiling a Windows app on Linux? Linux 上 Windows 的交叉编译提升 - Cross-compiling boost for Windows on Linux 提升未定义的引用,将Linux交叉编译到Windows - Boost undefined references cross compiling linux to windows 在Linux上与Eclipse交叉编译,在Windows上与Eclipse交叉编译? - cross compiling with Eclipse on linux and eclipse on windows? 在Linux for Windows上交叉编译boost光纤库 - Cross compiling boost fiber library on Linux for Windows 在Linux for Windows上交叉编译Qt5 - Cross Compiling Qt5 on Linux for Windows 当交叉编译(Linux 到 Windows)Vulkan 加载器时,有许多对 Vulkan 对象的未定义引用 - When Cross Compiling (Linux to Windows) The Vulkan Loader There Are Many Undefined References to Vulkan Objects 从 Linux 交叉编译到 Windows 时,MinGW 无法链接指定的库 - MinGW cannot link libraries specified when cross-compiling from Linux to Windows
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM