Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 10 Nov 2002 15:41:38 +0100
From:      Dag-Erling Smorgrav <des@ofug.org>
To:        Jonathon McKitrick <jcm@FreeBSD-uk.eu.org>
Cc:        freebsd-chat@freebsd.org, freebsd-questions@freebsd.org
Subject:   Re: Unresolved reference compiling Objective-C ??
Message-ID:  <xzpvg35xza5.fsf@flood.ping.uio.no>
In-Reply-To: <20021108173235.GA82490@dogma.freebsd-uk.eu.org> (Jonathon McKitrick's message of "Fri, 8 Nov 2002 17:32:35 %2B0000")
References:  <20021108173235.GA82490@dogma.freebsd-uk.eu.org>

next in thread | previous in thread | raw e-mail | index | archive | help
Jonathon McKitrick <jcm@FreeBSD-uk.eu.org> writes:
> dogma:...files/programs/objc> gcc -lobjc main.m printer.m -o testme
                                    ------

In source code, you have to define (or at least declare) symbols
before you reference them.  When linking, it's the other way around -
the linker only includes objects it knows are needed because they
define symbols which were referenced by previously included objects.
I don't know about Objective C, but what happens for plain C is this:
the linker starts out knowing it needs the entry point (called
_start).  It reads the run-time library (crt.o), which contains _start
and references but does not define main, which is added to the list of
unresolved symbols.  Then it reads the first object file specified,
which hopefully defines main and references a bunch of other symbols
which are defined in object files and libraries specified later on the
command line, and so forth until there are no more unresolved symbols.

In other words: always specify libraries at the end of the compiler or
linker command line.

DES
-- 
Dag-Erling Smorgrav - des@ofug.org

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?xzpvg35xza5.fsf>