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:
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.