From mint-bounce@lists.fishpool.fi Wed Jun 30 19:36:28 2010 Message-ID: <4C2BD466.60202@freesbee.fr> Date: Thu, 01 Jul 2010 01:33:58 +0200 From: =?ISO-8859-1?Q?Vincent_Rivi=E8re?= User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.9.2.4) Gecko/20100608 Thunderbird/3.1 MIME-Version: 1.0 To: mint@lists.fishpool.fi Subject: Re: [MiNT] Problems linking lib that uses the constructor __attribute References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed X-ecartis-version: Ecartis v1.0.0 Sender: mint-bounce@lists.fishpool.fi Errors-to: mint-bounce@lists.fishpool.fi X-original-sender: vincent.riviere@freesbee.fr Precedence: bulk List-help: List-unsubscribe: List-Id: X-List-ID: List-subscribe: List-owner: List-post: Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by mail.sparemint.org id o5UNaSlw011347 m0n0 wrote: > It seems gcc is only adding it to ctor if it is already > referenced... Yes, you are right. This is because of the rule: "A .o file located inside a static library will be linked only if some other previously linked object require it". However, the .o file contains the special __attribute__((constructor)) to auto register itself, but only when it is already linked :-( So the only solution is to force the linkage of the .o file containing the SDL frontend: - by adding a reference to any public symbol defined in the file containing the __attribute__((constructor)). This may be a reference to sdl_register_frontend() (like you posted in your other message) or a reference to another public function or variable defined in the same file. - or : > There is an trick to make it compile correctly: use the > -Wl,--whole-archive flag, but Vincent told me to not use this flag ... :) I told this should not be used, except in very special cases... like this one :-) But his method is inefficient, because it will really include all the contents of the library into your final executable, including useless .o files. This will work, but it will also highly increase the size of your executable. I don't know a clean solution for this problem. Your ugly method is probably the best - until someone has a better idea. -- Vincent Rivière