Boost logo

Boost Users :

Subject: Re: [Boost-users] Fwd: Getting ASIO application to link (undefined reference to `boost::system::generic_category()) (SOLVED)
From: Lars Viklund (zao_at_[hidden])
Date: 2013-09-18 11:20:06


On Wed, Sep 18, 2013 at 12:47:12PM +0200, Bjorn Reese wrote:
> On 09/18/2013 08:40 AM, Ulf Samuelsson wrote:
>
>> No, the solution is simple. The -l<library> must be AFTER the reference
>> to the object files.
>>
>> FAIL: g++ -lboost_system myfile.o
>> OK: g++ myfile.o -lboost_system
>>
>> Maybe there is a good reason for this.
>
> Many linkers are single-pass linkers because that gives better linking
> speed. See "The linking process" section of:
>
> http://eli.thegreenplace.net/2013/07/09/library-order-in-static-linking/

As touched on in the article linked, the ability to override functions
by sneaking in a library providing the function before the usual
provider is considered a feature by some.

If you want arbitrary ordering on the linker command line, some linkers
offer --start-group and --end-group directives that spin the libraries
bounded by the directives enough times to satisfy as many symbols as
possible.

Otherwise, the short form of the linker command line order advice is:
Stuff that needs stuff needs to be before stuff that provides stuff.

-- 
Lars Viklund | zao_at_[hidden]

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net