Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Magic main causing troble

Credits go to DanielH and miran for helping out!
This thread is locked; no one can reply to it. rss feed Print
Magic main causing troble
Per Larsson
Member #276
April 2000
avatar

Me and a friend are writing a library using allegro and SDL as a back-end (links with what's available when you compile it). There is however a problem when we make a program that links to our library, if we compile the library with allegro support enabled. I think it has to do with allegro's magic main, as we get the following error:

/usr/lib/liballeg.so.4.0: undefined reference to `_mangled_main_address'
collect2: ld returned 1 exit status

Note that we don't include allegro.h in either our library or the program using it, we are still working on the SDL part.

________________________
Guichan!

kazzmir
Member #1,786
December 2001
avatar

int main(){
init code..
award winning game loop..
cleanup code..
}
END_OF_MAIN()

did you forget END_OF_MAIN()?

if you arent using allegro, then why link in the library?

Per Larsson
Member #276
April 2000
avatar

OK, here's the deal. We are writing a GUI library which we want to be compatible with both SDL and allegro. When you compile the library it links with allegro, if you have allegro, and with SDL, if you have SDL. We are still working on the SDL-part, and haven't started with allegro yet, but allegro gets linked in when we compile our library, from the makefile.

It seems like using a library that is linked with allegro requires you to use END_OF_MAIN(), even if you don't use allegro in the rest of your application. And we were hoping there was some kind of clever workaround for this.

________________________
Guichan!

DanielH
Member #934
January 2001
avatar

#define ALLEGRO_NO_MAGIC_MAIN

only works for Windows

for linux there is not workaround as stated in the docs

miran
Member #2,407
June 2002

Quote:

but allegro gets linked in when we compile our library

That doesn't make sense. You do not link a library in when you compile another library. A library is just a collection of object files which you then link with some other object files to make an executable...

--
sig used to be here

Per Larsson
Member #276
April 2000
avatar

miran: hmm.. i guess you are right. So if we remove -lalleg when compiling the library it should work? Or do we have to declare dependency on allegro in another way?

________________________
Guichan!

DanielH
Member #934
January 2001
avatar

You will have to remove the header inclusion also. Otherwise you will still get the error.

Per Larsson
Member #276
April 2000
avatar

Problem solved.
Thanks for helping, everyone!

________________________
Guichan!

flares
Member #3,463
April 2003
avatar

from what i'm reading if you are still not working with the allegro part and olny the sdl then you shouldn't have -lalleg anywhere on your makefile since you are not using it. only link it and include it when you use it.

[nonnus29]Plus the api is crap ... I'd rather chew broken glass then code with those.

Go to: