[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[MiNT] Problems linking lib that uses the constructor __attribute
Hi there!
I'm having an library (libnsfb), this library can have several frontends,
also one that uses SDL...
The library provides an macro to register an frontend just by writing a
line of code into the frontend source code file.
Usually this function would be called by the C ctor (before main).
This is the macro:
#define NSFB_FRONTEND_DEF(__name, __type, __rtns) \
static void __name##_register_frontend(void)
__attribute__((constructor)); \
void __name##_register_frontend(void) { \
_nsfb_register_frontend(__type, __rtns, #__name); \
printf("0registered frontend: " #__name "\n"); \
}
Here's how it is used:
NSFB_FRONTEND_DEF( sdl, TYPE_SDL, somestruct) ;
Here's my example program that uses the lib:
#include <libnsfb.h>
int main(void)
{
enum nsfb_frontend_e fetype;
/*sdl_register_frontend();*/
fetype = nsfb_frontend_from_name("sdl");
if (fetype == NSFB_FRONTEND_NONE) {
printf("The %s frontend is not available from libnsfb\n", "sdl");
}
return (0);
}
If I compile / link that - it tell's me that sdl frontend is not
available.
If I uncomment sdl_register_frontend() the sdl frontend is registered
twice. It seems gcc is only adding it to ctor if it is already
referenced...
This is not an generic problem with the constructor attribute, I tested it
successfully with my own dummy/foobar lib.
Has anyone an tip on how to force gcc to put this function into the CTOR?
I tried to remove static / add volatile and -O0 - without success.
There is an trick to make it compile correctly: use the
-Wl,--whole-archive flag, but Vincent told me to not use this flag ... :)
Anyone knowns an trick?
Greets,
Ole