From owner-freebsd-questions Sun Nov 10 6:41:44 2002 Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 5A6EB37B401; Sun, 10 Nov 2002 06:41:43 -0800 (PST) Received: from flood.ping.uio.no (flood.ping.uio.no [129.240.78.31]) by mx1.FreeBSD.org (Postfix) with ESMTP id 35ECC43E3B; Sun, 10 Nov 2002 06:41:42 -0800 (PST) (envelope-from des@ofug.org) Received: by flood.ping.uio.no (Postfix, from userid 2602) id 2066B534E; Sun, 10 Nov 2002 15:41:39 +0100 (CET) X-URL: http://www.ofug.org/~des/ X-Disclaimer: The views expressed in this message do not necessarily coincide with those of any organisation or company with which I am or have been affiliated. To: Jonathon McKitrick Cc: freebsd-chat@freebsd.org, freebsd-questions@freebsd.org Subject: Re: Unresolved reference compiling Objective-C ?? References: <20021108173235.GA82490@dogma.freebsd-uk.eu.org> From: Dag-Erling Smorgrav Date: Sun, 10 Nov 2002 15:41:38 +0100 In-Reply-To: <20021108173235.GA82490@dogma.freebsd-uk.eu.org> (Jonathon McKitrick's message of "Fri, 8 Nov 2002 17:32:35 +0000") Message-ID: Lines: 23 User-Agent: Gnus/5.090007 (Oort Gnus v0.07) Emacs/21.2 (i386--freebsd) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Jonathon McKitrick 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