From mint-bounce@lists.fishpool.fi Wed Jun 30 19:05:21 2010 To: mint Subject: [MiNT] Problems linking lib that uses the constructor =?UTF-8?Q?=5F=5Fattribute?= MIME-Version: 1.0 Date: Thu, 01 Jul 2010 01:01:22 +0200 From: m0n0 Reply-To: ole@monochrom.net Message-ID: X-Sender: ole@monochrom.net User-Agent: Host Europe Webmailer/2.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 X-HE-Access: Yes X-bounce-key: webpack.hosteurope.de;ole@monochrom.net;1277938882;c49d432b; X-ecartis-version: Ecartis v1.0.0 Sender: mint-bounce@lists.fishpool.fi Errors-to: mint-bounce@lists.fishpool.fi X-original-sender: ole@monochrom.net Precedence: bulk List-help: List-unsubscribe: List-Id: X-List-ID: List-subscribe: List-owner: List-post: 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 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