Allegro.cc - Online Community

Allegro.cc Forums » Installation, Setup & Configuration » Having trouble with static linking

This thread is locked; no one can reply to it. rss feed Print
Having trouble with static linking
Michael Weiss
Member #223
April 2000

I am new to static linking, have always used dynamic with no problem.
I though I would try static, but can't get it working yet.

- First of all, what are the advantages of static vs dynamic?

- Second, what extra files do I need to include with my game?

With dynamic it seems I need:
allegro_monolith-5.2.dll (15,218K)
libgcc_s_dw2-1.dll (112K)
libstdc++-6.dll (1,504K)
libwinpthread-1.dll (46K)

I don't know what static will require as I havent been able to get it working yet.

I am using:

mingw-w64
Version:7.2.0
Architecture:i686
Threads:posix
Exception:dwarf
Build revison:1

Allegro 5.2.4 (from source)

Code::Blocks 17.12

I built both the dynamic and static monolith debug release versions of allegro

The only thing I did different for static was uncheck the SHARED flag in CMake

I changed the linker library list from:
-lallegro_monolith.dll
-lzlib
-lnet
-lwsock32

to:
-lallegro_monolith-static
-ljpeg
-ldumb
-lFLAC
-lfreetype
-lvorbisfile
-lvorbis
-logg
-lphysfs
-lpng16
-lzlib
-ldsound
-lgdiplus
-luuid
-lkernel32
-lwinmm
-lpsapi
-lopengl32
-lglu32
-luser32
-lcomdlg32
-lgdi32
-lshell32
-lole32
-ladvapi32
-lws2_32
-lshlwapi
-lnet
-lwsock32

I also set these compiler flags:
Static libgcc [-static-libgcc]
Static libstdc++ [-static-libstdc++]
Static linking [-static]

My project compiles, links and runs fine with dynamic linking.
But I am getting linker errors when I try static.

There seem to be 2 things linker can't find:

fixed point routines in fmaths.inl:
C:\mingw32\include\allegro5\inline\fmaths.inl|46|undefined reference to `_imp__al_fixtorad_r'|

and opus stuff:
C:\devel\Allegro5\addons\acodec\opus.c|102|undefined reference to `op_free'|

I am lost here. I don't know how to fix these errors.
I barely understand how I got this far...

Any advice on static vs dynamic as it applies to Allegro would be greatly appreciated.

Do I even want or need to do this?
Should I just use dynamic and not worry about static?

EDIT:

I just figured out the opus stuff..

I copied libopus.a and libopusfile.a from the dependencies
and linked to it with
-lopusfile
-lopus

still have the fmaths.inl errors...

Neil Roy
Member #2,229
April 2002
avatar

My own linker settings I use to compile my Allegro 5 game Deluxe Pacman 2 are the following, in order I have them in Code::Blocks. My game statically links without problems. I built this version of Allegro myself as well (which was a first for me, yay). Edit: all under Windows 7

mingw32
dumb
FLAC
vorbisfile
vorbis
freetype
ogg
physfs
png16
zlibstatic
gdiplus
uuid
kernel32
winmm
psapi
opengl32
glu32
user32
comdlg32
gdi32
shell32
ole32
advapi32
ws2_32
shlwapi
dsound
jpeg
opusfile
opus
allegro_monolith-static or allegro_monolith-debug-static

I also have the following on the side for other linker options;

-static
-static-libgcc

---
“I love you too.” - last words of Wanda Roy

Elias
Member #358
May 2000

I think you have to also compile your code with -DALLEGRO_STATICLINK, that could explain the fmaths error.

--
"Either help out or stop whining" - Evert

Michael Weiss
Member #223
April 2000

Thanks Neil,

I actually found a old post of your with that linker list that I was comparing to mine...

Thanks Elias,

Using -DALLEGRO_STATICLINK worked
I made my own entry in compiler settings -> compiler flags
and it linked and ran...Thanks again

Neil Roy
Member #2,229
April 2002
avatar

I usually just have: #define ALLEGRO_STATICLINK at the top of one or more of my source files, didn't mention it. Never thought to use the command line argument.

Edit: Yeah, I just changed my own code to use -DALLEGRO_STATICLINK as an argument instead and it works. I like that better. The next time someone needs help, I can include that in my list of arguments I post here. Seems like the safer bet than remembering if you included it in your code somewhere.

---
“I love you too.” - last words of Wanda Roy

Go to: