|
Static Linking |
Tonto_
Member #10,690
February 2009
|
I am trying to use static linking in my project and at run-time, strange things seem to happen, like access violations where in regular linking mode they work fine! I can't really understand why this happens but I have in my code just the preprocessor options to do static linking or not and when I do static linking, it makes my data file and bitmap loading functions fail for some reason! I get access violations trying to load the bitmaps In debug mode, static link it fails in _stub_bank_switch Is there something that I might be overlooking or might be blind to |
Timorg
Member #2,028
March 2002
|
allegro/docs/build/mingw32.txt said:
When using a statically linked library, you must define the preprocessor The symbol ALLEGRO_STATICLINK is important for linux, I don't know the required arguments to allegro-config off the top of my head. ____________________________________________________________________________________________ |
Tonto_
Member #10,690
February 2009
|
I did everything as the quoted text says but I don't know what you mean by this: "I don't know the required arguments to allegro-config off the top of my head." |
LennyLen
Member #5,313
December 2004
|
Quote: but I don't know what you mean by this: "I don't know the required arguments to allegro-config off the top of my head." If you're compiling for Windows then you don't need to worry about it.
|
Tonto_
Member #10,690
February 2009
|
Minimal example demonstrates my troubles. It crashes on load_bitmap with an access violation in a bitmap line reading routine. I am running 4.2.2 with Microsoft Visual Studio 2008 on Windows XP
The program crashes with an access violation in the runtime when I do the load_bitmap line. Also on load_datafile, load_font or anything, and I just don't know why. It errors here: uintptr_t _stub_bank_switch(BITMAP *bmp, int y) { return (uintptr_t)bmp->line[y]; }
|
Milan Mimica
Member #3,877
September 2003
|
Smells like the the old non-ASM bug on Windows. And yes, it's fixed in 4.3.10+ branch. Can you recompile your program with a ALLEGRO_NO_ASM preprocessor flag?
-- |
Tonto_
Member #10,690
February 2009
|
That preprocessor define works. I don;'t exactly even understand the problem but that fixes the linkage with alleg_s. I also wanted to try using alleg_s_crt.lib because vista always complains about like the SxS and the runtime libraries I tried compiling it with alleg_s_crt first in the list for my linker options in vc++ 2008 but it failed with
Maybe I just need to fiddle with it somemore somehow |
Edgar Reynaldo
Major Reynaldo
May 2007
|
Did you follow the directions in allegro\docs\build\msvc.txt : Quote:
When using a statically linked library, you must define the preprocessor If that doesn't work, you can post your project file for MSVC, and others can verify if your settings are correct. (Not me though, because I don't have MSVC). What about setting the appropriate link libraries in your project options instead of using #pragma to do it? There is another set of libraries that you have to link against when linking statically to allegro : -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lole32 -ldinput -lddraw -ldxguid -lwinmm -ldsound Link to those after linking to allegro. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Tonto_
Member #10,690
February 2009
|
The settings I tried to use to make it work with allegro_s_crt: /MT - Multi-threaded run time library as is the allegro_s_crt, different from /MD, used for the msvcrt dll Additional dependencies: alleg_s_crt.lib dinput.lib ddraw.lib dxguid.lib winmm.lib dsound.lib Project file here: http://zxcvbn.googlecode.com/svn/trunk/pixelvalentine/Allegro%20Test%202/Allegro%20Test%202.vcproj Should I be trying to do this at all? I was just annoyed that when I try to share my app the users get SxS errors and have to get the vcredist. Edit: Also it occured to me, that I am using C++ -- not any C++ libraries but it is compiling as C++, will this mess up the linker symbols and make this whole thing not work? |
Milan Mimica
Member #3,877
September 2003
|
I find it a good idea to have as much possible linked statically, even the CRT. And no, no need to compile your code as C++ if you use only C, but it will release you from many restrictions that C89 (the newest C that MSVC supports) imposes.
-- |
Edgar Reynaldo
Major Reynaldo
May 2007
|
Quote: Edit: Also it occured to me, that I am using C++ -- not any C++ libraries but it is compiling as C++, will this mess up the linker symbols and make this whole thing not work? If you're compiling C code to be linked with C++ code, then you should wrap the C function declarations in extern "C" {/*....*/} to have those functions use C linkage. However if you're just compiling it as C++ instead then you shouldn't have any problems aside from making any necessary conversions to C++. Quote: Additional dependencies: alleg_s_crt.lib dinput.lib ddraw.lib dxguid.lib winmm.lib dsound.lib You're missing several libraries from the list in my last post - allegro needs to be linked to those, and that's why there are undefined reference errors. Specifically, you missed these between linking to allegro and the rest of the libraries : -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lole32 So it seems you need to add kernel32.lib, user32.lib, gdi32.lib, comdlg32.lib, and ole32.lib to your additional dependencies. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Tonto_
Member #10,690
February 2009
|
I did a dumpbin on allegro_s_crt.lib and I couldn't find any normal crt functions, but a couple did say like al_srand or al_blah. Does this mean I use the al_* function calls to use the static allegro crt? This is what the dumpbin looks like if anyone is curious: |
Edgar Reynaldo
Major Reynaldo
May 2007
|
Quote: Does this mean I use the al_* function calls to use the static allegro crt? No, just use the normal functions allegro provides access to. You don't need to use a different set of functions to link to the same library. Did you add the other dependencies for static linking? My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Thomas Fjellstrom
Member #476
June 2000
|
Quote: Does this mean I use the al_* function calls to use the static allegro crt? Allegro doesn't provide access to any C runtime symbols. Just its own API. In addition, static linking means you need to link to allegro's dependencies manually since you can't link things directly to a static lib. -- |
|