Properly static-linking MinGW Windows DLL

I'm on x64 Windows 8 and I want to release an binary without dll's.

I was learning DirectX (9), using Code::Blocks (13) and the 32-bit MinGW-build (4.8) with -lpthread.
I build an standard Code::Blocks DirectX 9 project. Edited to 32-bits for both x86 and x64 and run. Ok. Then I said for my friend run it on his 64-bit computer, but he got 2 library errors: "libgcc_s_dw2-1.dll" and "libwinpthread-1.dll". After that I tryed to compile from cmd and I got errors even when including -ld3d9 and -ld3dx9. Googled up and found -static-libgcc, -static-libstdc++ and -static. None work. So, what should I do? In command prompt, I tryed:
1
2
3
C:\CPP\DirectX_test>g++ -m32 -mwindows -static -static-libgcc -static-libstdc++
-lpthread -I"C:\Program Files (x86)\Microsoft DirectX SDK\Include" -L"C:\Program
 Files (x86)\Microsoft DirectX SDK\lib" -ld3d9 -ld3dx9 main.cpp -o DirectX_test

And got undefined reference to 'Direct3DCreate9@4' (http://s22.postimg.org/malxvenzl/error.png)

And on Code::Blocks, I have the following "Other options" in Compiler:
 
-m32 -static -static-libgcc -static-libstdc++ -lwinpthread -Wl,--subsystem,windows -mwindows

And the compiling by Code::Blocks is
1
2
3
4
5
g++.exe -DWIN32 -DNDEBUG -D_WINDOWS -D_MBCS -Wall -O2 -std=c++11 -m32 -static -static-libgcc -static-libstdc++ -lwinpthread -Wl,--subsystem,windows -mwindows -I"C:\Program Files (x86)\Microsoft DirectX SDK\include" -c C:\CPP\DirectX_test\main.cpp -o obj\Release\main.o

then

g++.exe -L"C:\Program Files (x86)\Microsoft DirectX SDK\lib" -L"C:\Program Files (x86)\Microsoft DirectX SDK\lib\x86" -o bin\Release\DirectX_test.exe obj\Release\main.o  -s  -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lodbc32 -lodbccp32 -ld3d9 -ld3dx9 -mwindows


and gave me 4 warnings:
1
2
3
4
5
6
||=== Build: Release in DirectX_test (compiler: GNU GCC Compiler) ===|
C:\Program Files (x86)\Microsoft DirectX SDK\include\d3d9types.h|25|warning: ignoring #pragma warning  [-Wunknown-pragmas]|
C:\Program Files (x86)\Microsoft DirectX SDK\include\d3d9types.h|2411|warning: ignoring #pragma warning  [-Wunknown-pragmas]|
C:\Program Files (x86)\Microsoft DirectX SDK\include\d3d9.h|2025|warning: "/*" within comment [-Wcomment]|
C:\Program Files (x86)\Microsoft DirectX SDK\include\d3d9.h|2026|warning: "/*" within comment [-Wcomment]|
||=== Build finished: 0 error(s), 4 warning(s) (0 minute(s), 1 second(s)) ===|

What should I do?
Your link paths are different on the Code::Blocks and command line versions. -L"C:\Program
Files (x86)\Microsoft DirectX SDK\lib"
vs -L"C:\Program Files (x86)\Microsoft DirectX SDK\lib\x86". This matters because the calling conventions for x86_64 and x86 are different, requiring different name mangling (AFAIK, x64 uses __fastcall).

EDIT:
If you really want static libraries, from what I've seen, it is very difficult to remove the dependency winpthread, so you should look into TDM-GCC (A version of MinGW that is statically linked by default).
Last edited on
Topic archived. No new replies allowed.