0

I use cmake to help to complie a appliction with MinGW32 on Windows 8.1 x64 system.

The goal is to make a application can be run in windows from Windows XP to Windows 10 .

Using the combination of static and dynamic compilation ,Since some dll cannot find static libraries。

some major code

SET(toolchain_lib   "E:/mingw32/lib" "E:/mingw32/lib/gcc/mingw32/5.3.0") 
LINK_DIRECTORIES(${toolchain_lib})
target_link_libraries(${TARGET_NAME}  
      libgdi32.a  
      libglu32.a    
      #freeglut.dll 
      freeglut.a  
      libglew32.a 
      #libglew32.dll.a
      opengl32.lib 
      libstdc++.a 
      libgcc.a 
) 
set(CMAKE_EXE_LINKER_FLAGS  "-static-libgcc -static-libstdc++ /SUBSYSTEM:WINDOWS,5.1")
FILE (GLOB SRC_LIST "${src}/*.cpp" "${inc}/*.h")
ADD_EXECUTABLE(${TARGET_NAME} ${SRC_LIST})

cmake response:

[100%] Linking CXX executable ..\bin\sample_cube_picturebox_t.exe
g++.exe: error: /SUBSYSTEM:WINDOWS,5.1: No such file or directory
CMakeFiles\sample_cube_picturebox_t.dir\build.make:200: recipe for target '../bin/sample_cube_picturebox_t.exe' failed
make.exe[2]: *** [../bin/sample_cube_picturebox_t.exe] Error 1
CMakeFiles\Makefile2:81: recipe for target 'CMakeFiles/sample_cube_picturebox_t.dir/all' failed
make.exe[1]: *** [CMakeFiles/sample_cube_picturebox_t.dir/all] Error 2
Makefile:89: recipe for target 'all' failed
bin\make.exe: *** [all] Error 2
arrowd
  • 33,231
  • 8
  • 79
  • 110
anti-gravity
  • 122
  • 6
  • 2
    Are you sure that `/subsystem` is a valid mingw option? Because the syntax looks very much like msvc. – BDL Jul 26 '21 at 18:00
  • **Do not use globs without `CONFIGURE_DEPENDS`**, or better yet, do not use globs at all. See [here](https://stackoverflow.com/a/65191951/2137996). – Alex Reinking Jul 27 '21 at 16:17
  • 1
    Windows XP has been end-of-life for quite a while now. Continuing to support it only supports people's decision to not migrate which, given the abundance of vulnerabilities that will _never_ be patched, is unjustifiable. – Alex Reinking Jul 27 '21 at 16:20

1 Answers1

1

/SUBSYSTEM:WINDOWS,5.1 is not a GCC flag.

You probably want to use something line -D_WIN32_WINNT=0x0501 to specify Windows XP compatibility (see: https://learn.microsoft.com/en-us/cpp/porting/modifying-winver-and-win32-winnt?view=msvc-160)

Brecht Sanders
  • 6,215
  • 1
  • 16
  • 40