[PATCH] linking stdc++ and libgcc statically in windows

Discussion of development and patch submission.
roytam1
Posts: 14
Joined: Mon 27 Oct, 2014 2:27 am

[PATCH] linking stdc++ and libgcc statically in windows

Postby roytam1 » Tue 18 Nov, 2014 12:20 am

I think it is better to link stdc++ and libgcc statically (using "-static-libgcc -static-libstdc++" switch) to reduce redist package size.

Code: Select all

--- Makefile.mingw.orig   2014-11-17 20:41:02 +0800
+++ Makefile.mingw   2014-11-18 10:39:49 +0800
@@ -23,14 +23,14 @@
    win-status.o win-time.o win-video.o x86seg.o x87.o xtide.o pc.res
 FMOBJ = dbopl.o
 SIDOBJ = convolve.o envelope.o extfilt.o filter.o pot.o sid.o voice.o wave6581__ST.o wave6581_P_T.o wave6581_PS_.o wave6581_PST.o wave8580__ST.o wave8580_P_T.o wave8580_PS_.o wave8580_PST.o wave.o
 
 
-LIBS = -mwindows -lwinmm -lalut -lopenal32 -lddraw -ldinput -ldxguid -ld3d9 -lstdc++
+LIBS = -mwindows -lwinmm -lalut -lopenal32 -lddraw -ldinput -ldxguid -ld3d9 -static-libstdc++ -static-libgcc
 
 PCem.exe: $(OBJ) $(FMOBJ) $(SIDOBJ)
-   $(CC) $(OBJ) $(FMOBJ) $(SIDOBJ) -o "PCem.exe" $(LIBS)
+   $(CPP) $(OBJ) $(FMOBJ) $(SIDOBJ) -o "PCem.exe" $(LIBS)
 
 all : PCem.exe
 
 clean :
    del *.o
truth
Posts: 26
Joined: Thu 06 Nov, 2014 3:15 am

Re: [PATCH] linking stdc++ and libgcc statically in windows

Postby truth » Tue 18 Nov, 2014 3:05 am

That doesn't work on newer mingw/gcc installations.
roytam1
Posts: 14
Joined: Mon 27 Oct, 2014 2:27 am

Re: [PATCH] linking stdc++ and libgcc statically in windows

Postby roytam1 » Tue 18 Nov, 2014 3:07 am

truth wrote:That doesn't work on newer mingw/gcc installations.

Any error messages?

BTW It works for me. ;)

Code: Select all

/d/PCem/src$ gcc -v
Using built-in specs.
COLLECT_GCC=D:\msys\mingw\bin\gcc.exe
COLLECT_LTO_WRAPPER=d:/msys/mingw/bin/../libexec/gcc/i686-w64-mingw32/4.8.1/lto-wrapper.exe
Target: i686-w64-mingw32
Configured with: ../source/gcc-4.8.1/configure --build=x86_64-unknown-linux-gnu --target=i686-w64-mingw32 --host=i686-w64-mingw32 --disable-shared --enable-static --disable-nls --disable-multilib --prefix=/home/hendrik/mingw/target/mingw-w64-i686 --with-sysroot=/home/hendrik/mingw/target/mingw-w64-i686 --with-mpc=/home/hendrik/mingw/target/packages/gcc/packages/mpc/mpc-1.0.1-x86_64 --with-mpfr=/home/hendrik/mingw/target/packages/gcc/packages/mpfr/mpfr-3.1.2-x86_64 --with-gmp=/home/hendrik/mingw/target/packages/gcc/packages/gmp/gmp-5.1.2-x86_64 --with-host-libstdcxx='-lstdc++ ' --with-cloog=/home/hendrik/mingw/target/packages/gcc/packages/cloog/cloog-0.18.0-x86_64 --with-isl=/home/hendrik/mingw/target/packages/gcc/packages/isl/isl-0.11.1-x86_64 --enable-languages=c,c++ --enable-threads=win32 --enable-fully-dynamic-string
Thread model: win32
gcc version 4.8.1 (GCC)
/d/PCem/src$ ld --version
GNU ld (GNU Binutils) 2.23.2
Copyright 2012 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) a later version.
This program has absolutely no warranty.
truth
Posts: 26
Joined: Thu 06 Nov, 2014 3:15 am

Re: [PATCH] linking stdc++ and libgcc statically in windows

Postby truth » Tue 18 Nov, 2014 3:13 am

Test with gcc 4.8.2 to verify and by compiling on native win32 (not cross-compiling on another OS).
roytam1
Posts: 14
Joined: Mon 27 Oct, 2014 2:27 am

Re: [PATCH] linking stdc++ and libgcc statically in windows

Postby roytam1 » Tue 18 Nov, 2014 3:16 am

truth wrote:Test with gcc 4.8.2 to verify and by compiling on native win32 (not cross-compiling on another OS).

I wonder if you miss this part:

Code: Select all

 PCem.exe: $(OBJ) $(FMOBJ) $(SIDOBJ)
-   $(CC) $(OBJ) $(FMOBJ) $(SIDOBJ) -o "PCem.exe" $(LIBS)
+   $(CPP) $(OBJ) $(FMOBJ) $(SIDOBJ) -o "PCem.exe" $(LIBS)
therock247uk
Posts: 29
Joined: Fri 25 Apr, 2014 2:55 pm

Re: [PATCH] linking stdc++ and libgcc statically in windows

Postby therock247uk » Tue 18 Nov, 2014 3:24 am

What would be nice is a pcem build that requires no external dll's but the main problem is ppl not including them in builds (not sure the real reason why) distributing it with out the dlls is useless you may as well not bother at all as its very version dll specific you cant just get them from the internet and expect it to work. unless you have the mingw dirs in your system path (worst thing you can ever do)
Last edited by therock247uk on Tue 18 Nov, 2014 3:36 am, edited 1 time in total.
roytam1
Posts: 14
Joined: Mon 27 Oct, 2014 2:27 am

Re: [PATCH] linking stdc++ and libgcc statically in windows

Postby roytam1 » Tue 18 Nov, 2014 3:28 am

therock247uk wrote:What would be nice is a pcem build that requires no external dll's but the main problem is ppl not including them in builds (not sure the real reason why) distributing it with out the dlls is useless you may as well not bother at all as its very version dll specific you cant just get them from the internet and expect it to work.

yeah.

For now I can link libalut statically as well (but it requires exporting symbols from EXE(which may look a bit odd) or modifying alut.h NOT to put anything in ALUT_API macro) so PCem will require openal32.dll only.

for odd-but-easy way, modifying soundopenal.c Adding:

Code: Select all

#define ALUT_BUILD_LIBRARY

before

Code: Select all

#include <AL/alut.h>

place libalut.a to $LIBPATH and thats it.
truth
Posts: 26
Joined: Thu 06 Nov, 2014 3:15 am

Re: [PATCH] linking stdc++ and libgcc statically in windows

Postby truth » Tue 18 Nov, 2014 3:57 am

It is documented on Vogons that newer versions of mingw/gcc will not build against static runtime libraries. Furthermore, statically compiling certain libraries will break multithreading operations. This is also documented.
roytam1
Posts: 14
Joined: Mon 27 Oct, 2014 2:27 am

Re: [PATCH] linking stdc++ and libgcc statically in windows

Postby roytam1 » Tue 18 Nov, 2014 4:09 am

truth wrote:It is documented on Vogons that newer versions of mingw/gcc will not build against static runtime libraries. Furthermore, statically compiling certain libraries will break multithreading operations. This is also documented.

I'd file bug report to such libraries instead. :P
SarahWalker
Site Admin
Posts: 1311
Joined: Thu 24 Apr, 2014 4:18 pm

Re: [PATCH] linking stdc++ and libgcc statically in windows

Postby SarahWalker » Tue 18 Nov, 2014 8:29 am

The thing that confuses me about this is that my builds always have stdc++ and libgcc linked statically, and only OpenAL linked dynamically, using the same Makefile as everyone else. What am I doing differently?
truth
Posts: 26
Joined: Thu 06 Nov, 2014 3:15 am

Re: [PATCH] linking stdc++ and libgcc statically in windows

Postby truth » Tue 18 Nov, 2014 5:37 pm

The c/c++ runtimes may be dynamically linked but located in another directory than pcem (win32), such as the /bin directory of mingw which is typically a directory in the user's PATH. At least this is my experience with the newer gcc versions and I could verify again. I use gcc 4.6.x to avoid the issue. Further, the gcc 4.8.x has bugs, including the problem in defaulting to at least one parameter which breaks some existing software, the same software which builds correctly with older gcc versions.

I haven't tested the possibility of whether the runtimes are linking statically yet requiring a dynamic link, too (in the newer gcc versions). One method is to copy the files to a system without mingw and see if the expected error occurs.
ZummiGummi
Posts: 3
Joined: Wed 10 Dec, 2014 9:23 pm

Re: [PATCH] linking stdc++ and libgcc statically in windows

Postby ZummiGummi » Wed 10 Dec, 2014 9:31 pm

Just wanted to say, that using roytam1's instructions, I was able to compile PCEM, to only require OpenAL32.dll. So thank you.

Return to “Development”

Who is online

Users browsing this forum: No registered users and 2 guests