2x larger SDL2.dll file

I didn’t see this flag because it was hidden. The Advanced checkbox should be checked:

image

Here are some instructions: Build optimized library:

cmake ~/SDL -DCMAKE_BUILD_TYPE=Release
cmake --build . --config Release

I tried with CMAKE_CXX_FLAGS_RELEASE = -O3 -DNDEBUG and with --config Release. I deleted the dist folder before configuration:

cmake --build dist --config Release
cmake --install dist

But SDL3.dll = 17.9 MB

I set CMAKE_CXX_FLAGS_RELEASE to -O2 instead of -O3 -DNDEBUG and built with cmake --build dist --config Release. Result: 16.5 MB. It is minus 1.4 MB for Release but Debug is 12.0 MB

I wanted to know and tried it.

  • Linux:

    • Debug :10.8MB
    • Release: 3.6MB
  • Windows:

    • Debug: 13.1MB
    • Release: 21.4MB

Interestingly, Linux and Windows behave differently.

1 Like

You should check which section is taking up space. (I use SDL3 as an example, but you can do the same with SDL2).

# check file size
$ du -h SDL3.dll 
21M     SDL3.dll

# list sections and sort them by size
$ x86_64-w64-mingw32-objdump -h SDL3.dll | awk '/^ +[0-9]+ +\./ {print $3, $2 }' | sort -r
007294c9 .debug_info
005a2b07 .debug_loc
0022af08 .text
001d90ff .debug_line
0011d580 .debug_ranges
0005d910 .rdata
00050398 .debug_frame
000430f4 .debug_str
0003e6db .debug_abbrev
00015d03 .debug_loclists
00011094 .pdata
0000fd88 .xdata
00007a00 .edata
00007590 .data
00003b8d .debug_line_str
000038e0 .debug_aranges
00003720 .idata
00003460 .bss
00002aa0 .reloc
00000ee9 .debug_rnglists
00000318 .rsrc
00000058 .CRT
00000010 .tls

As you can see, the .debug sections are the culprit.

# strip debug symbols
$ x86_64-w64-mingw32-strip -s SDL3.dll

# check size again...
$ du -h SDL3.dll 
2.8M    SDL3.dll

If you still want to make it smaller, you could optimize for size and/or use a packer, as you did before; now it will be much more useful because there’s no more debug data to pack.
You can also add -s flag to linker to strip right after DLL is linked.

1 Like

Unfortunately, I don’t have Linux. I don’t have enough space on my laptop to install Linux on Virtual Box. I think it would require at least 5GB. There would be some program to use console commands, like in Linux, but on Windows.

It would be great if the CMake GUI had a single checkbox “Use OpenGL only” and “Use Vulkan only” that would disable everything else, even the extra .cpp files that are included. For example, I don’t need Vulkan. I only need OpenGL 2.1, OpenGL ES 2.0, and a joystick.

Unfortunately, I don’t have Linux. I don’t have enough space on my laptop to install Linux on Virtual Box. I think it would require at least 5GB. There would be some program to use console commands, like in Linux, but on Windows.

Fortunately, all these tools are available on Windows as part of the mingw-w64 package, you can also install MSYS2 to get a comfy POSIX-like environment. And of course you can skip all these steps I described and just strip the library or add the -s linker flag.

It would be great if the CMake GUI had a single checkbox “Use OpenGL only” and “Use Vulkan only” that would disable everything else, even the extra .cpp files that are included. For example, I don’t need Vulkan. I only need OpenGL 2.1, OpenGL ES 2.0, and a joystick.

There are more rendering backends, and it will require adding an option like this for each of them, and what if the user has both ONLY_VULKAN and ONLY_OPENGL enabled :grin: ?
Too much complexity for something that can be achieved with manual (and more precise) option control.

1 Like