[MSVC 10] Unresolved symbols when static linking to allegro 4.4.2
BitCruncher

I'm trying to static link with msvc 10 using /MT.

I'm inputting allegro-4.4.2-monolith-static-mt.lib to the linker, and I've also added ALLEGRO_STATICLINK to the preprocessor, but I still get:

Error 6 error LNK1120: 5 unresolved externals
Error 4 error LNK2001: unresolved external symbol _allegro_errno
Error 2 error LNK2001: unresolved external symbol _gfx_driver
Error 3 error LNK2001: unresolved external symbol _key
Error 5 error LNK2001: unresolved external symbol _screen
Error 1 error LNK2001: unresolved external symbol _system_driver

I thought monolith meant no others libraries required (libpng, libvorbis, etc.)

EDIT: I have also specified the lib directory.

RmBeer2

You also need to specify the directory where the library is located. (-L)

BitCruncher

Did that. I can verify it because if I take out the path, I get:

Error 1 error LNK1181: cannot open input file 'allegro-4.4.2-monolith-static-mt.lib'

Edgar Reynaldo

You need to define ALLEGRO_STATICLINK before including allegro if you're linking statically.

You'll also need to link the dependencies :

EDIT Sorry, I gave you A5, not A4 list

alleggl.lib
jpgalleg.lib
loadpng.lib
logg.lib
alleg-debug-static.lib
vorbis.lib
vorbisenc.lib
vorbisfile.lib
ogg.lib
png16.lib
zlibstatic.lib

kernel32.lib
user32.lib
gdi32.lib
comdlg32.lib
ole32.lib
dinput.lib
ddraw.lib
dxguid.lib
winmm.lib
dsound.lib

BitCruncher

Ok, I'll try it and give an update. I'm out of town right now.

Edgar Reynaldo

For when you get back....

BitCruncher

Bump. Still not back yet...

Edgar Reynaldo

Bump for your bump. ;)

RmBeer2

Bump x2 (Same day, more power)

BitCruncher

So it looks like from that list of items to link, I'm missing:

*vorbisenc.lib
*png16.lib

Just so you know, I downloaded the package from the files section on the site:

https://www.allegro.cc/files/?v=4.4

Edgar Reynaldo

And so, what's your error?

BitCruncher

The error now is the linker can't find dinput.lib, which is DirectInput, right?

EDIT
I went and downloaded dx70_min.zip from liballeg.org and put the libs in the VC libs directory.

Now, I'm back to the same linker errors as above except the unresolved _gfx_driver error is gone now.

_allegro_errno, _key, and _screen are all allegro, it's almost like something in the allegro static builds is missing...

EDIT #2
I got it down to 1 unresolved _main by switching from the Debug configuration to Release in VS.

DanielH

In your config, did you add those linker libraries to both DEBUG and RELEASE mode or just RELEASE mode?

How is your main function defined? Do you have END_OF_MAIN() at the end of main?

BitCruncher

The libs weren't included in the release configuration, but when I added them, no change.

I do have END_OF_MAIN() immediately after the closing bracket of main().

I've been researching, and I found a thread where the OP had a similar issue.

https://www.allegro.cc/forums/thread/594676

He fixed it by linking against alleg_s_crt.lib, but it must've been an earlier version of allegro than 4.4 because I don't have that file.

EDIT
Here's my code, but I don't think it's in there.

#SelectExpand
1# include <allegro.h> 2 3volatile long int coreClock = 0 ; 4 5 6void increment_coreClock () {++ coreClock ;} END_OF_FUNCTION () 7 8 9int main () 10{ 11 int screenResX = 800 ; 12 int screenResY = 600 ; 13 14 const float fullFrameRate = 60 ; // Maximum frame rate 15 float frameRatePercent = 100 ; // Percentage of the maximum frame rate that the game is run on 16 float frameRate = fullFrameRate / 100 * frameRatePercent ; // Actual frame rate that the game is run on 17 18 // Allegro initialization 19 allegro_init () ; 20 install_keyboard () ; 21 set_window_title ("") ; 22 set_color_depth (desktop_color_depth ()) ; 23 set_gfx_mode (GFX_AUTODETECT_FULLSCREEN, screenResX, screenResY, 0, 0) ; 24 install_timer () ; 25 LOCK_VARIABLE (coreClock) ; 26 LOCK_FUNCTION (increment_coreClock) ; 27 install_int_ex (increment_coreClock, BPS_TO_TIMER (frameRate)) ; 28 29 30 31 const int debugColor = makecol (0, 0, 255) ; // Color that the debugging information is written in 32 33 BITMAP* buffer = create_bitmap (screenResX, screenResY) ; 34 35 BITMAP* starBuffer = create_bitmap (1600, 1200) ; 36 BITMAP* starLayer = load_bitmap ("StarLayer2.bmp", NULL) ; 37 BITMAP* landscapeLayer = load_bitmap ("Starscape.bmp", NULL) ; 38 39 int rotateCounter [2] = {3, 3} ; 40 float rotateInc = 0.1 ; 41 float angle = 0 ; 42 43 44 45// ***************************** Begin game loop ******************************* 46 while (! key [KEY_ESC]) 47 { 48 while (! coreClock) {rest (100 / frameRate) ;} 49 while (coreClock > 0) 50 { 51 int oldTicks = coreClock ; 52 53 -- rotateCounter [0] ; 54 if (! rotateCounter [0]) 55 { 56 rotateCounter [0] = rotateCounter [1] ; 57 angle += rotateInc ; 58 } 59 60 61 62 -- coreClock ; 63 if (oldTicks <= coreClock) {break ;} 64 } 65 rotate_sprite (starBuffer, starLayer, 0, 0, ftofix (angle)) ; 66 blit (starBuffer, buffer, 400, 300, 0, 0, buffer->w, buffer->h) ; 67 draw_sprite (buffer, landscapeLayer, 0, 0) ; 68 vsync () ; 69 blit (buffer, screen, 0, 0, 0, 0, screenResX, screenResY) ; 70 } 71// ***************************** End game loop ********************************* 72 73// ***************************** Begin cleanup ********************************* 74 destroy_bitmap (buffer) ; 75 destroy_bitmap (starBuffer) ; 76 destroy_bitmap (starLayer) ; 77 destroy_bitmap (landscapeLayer) ; 78// ***************************** End cleanup *********************************** 79 return 0 ; 80} 81END_OF_MAIN ()

Edgar Reynaldo

Link against the library that came in the download. Don't try to 'fix' something that isn't broken.

If you don't have some of those libs, it's because that build of allegro didn't use them and so they are not necessary.

BitCruncher

Whoa okay, man. I won't link against any libraries I'm not told to. I promise.

So should I get rid of the DirectX stuff I added in the build script?

Edgar Reynaldo

Don't mistake my glibness for curtness.

You need some form of DX. For MSVC, that's usually taken care of by installing the DXSDK from Microsoft, but the dx7 download should work too.

I don't really know what else is wrong. If you're linking to the static allegro monolith and the dependency libraries it should work, because you've defined ALLEGRO_STATICLINK in your preprocessor defintions. The unresolved reference to _main or WinMain comes from not including END_OF_MAIN() at the end of your program, but you've done that.

Be patient, we're narrowing down the cause as best we can without being able to see your configuration.

BitCruncher

Actually, sharing my project configuration is a good idea I didn't think about.

As soon as I'm back at the cpu, I can just send the whole project, vs solution and all.

Edgar Reynaldo

Ok. Ready when you are. Put it in a zip file if you would. ;)

BitCruncher

Still alive, just busy with work...

Project is attached

Edgar Reynaldo

I'm sorry I can't help you. My version of MSVC has gone stale and my credentials are broken. Visual Studio will now exit. >:(

In the minute or so I was allowed to use VS, you're still not linking all the libraries.

BitCruncher

I'm pretty sure I've included all the libraries you listed minus the ones I don't have.

As I said a couple posts back, I do not have:

*vorbisenc.lib
*png16.lib

They did not come with the distribution. You can see this if you go and look at the archive file for msvs 10:

https://www.allegro.cc/files/?v=4.4

I'm not sure what else I'm supposed to include...

Edgar Reynaldo

Well, from the pictures it looks ok. Why are the allegro libraries on the solution and not in additional dependencies? I suppose it doesn't matter.

Anyway as I said I don't have a valid license for VS anymore. Big brother Bill saw I was using MinGW-W64 and CB and got jealous.

BitCruncher

I see... Well, I'm only doing this because I'm trying to revive some old code I wrote many years ago, and it would be nice if I could distribute it without the dlls.

I'll probably try to see if I have any luck with MinGW, but if I remember correctly, trying to build allegro with MinGW on a Windows machine was always like trying to build a house of cards in a pitch black room, and you're blind. But I'll give it another shot.

If all else fails, I guess dlls aren't so bad.

Edgar Reynaldo

So don't build it yourself!

I have binaries available for MinGW-W64 gcc 11.2 and Allegro 5.2.7.1 which you can find here :

https://github.com/EdgarReynaldo/EagleGUI/releases/tag/0pt8pt2alpha

There is a link to the version of MinGW-W64 I used (from winlibs.com).

BitCruncher

Do you have allegro 4 bins? I'm trying to not rewrite every legacy project I've got in A5...

Edgar Reynaldo

Oh! Sorry! Scatterbrained.....

http://bitbucket.org/bugsquasher

https://bitbucket.org/bugsquasher/unofficial-allegro-5-binaries/downloads/

Don't worry, there are A4 binaries there too. You can get the i686-posix-dwarf compiler for GCC 8.1 here :

https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/8.1.0/threads-posix/dwarf/i686-8.1.0-release-posix-dwarf-rt_v6-rev0.7z

Download https://bitbucket.org/bugsquasher/unofficial-allegro-5-binaries/downloads/A443Deluxe.7z

and you will get Allegro 4.4.3, AlFont, FreeType, jpg, png, logg, ogg, MASkinG and you could use my A4 GUI library Eagle4 (EagleClassic) https://github.com/EdgarReynaldo/EagleClassic

Thread #618515. Printed from Allegro.cc