From owner-freebsd-hackers Mon Nov 27 8:42:44 2000 Delivered-To: freebsd-hackers@freebsd.org Received: from homer.softweyr.com (bsdconspiracy.net [208.187.122.220]) by hub.freebsd.org (Postfix) with ESMTP id 2725837B479 for ; Mon, 27 Nov 2000 08:42:38 -0800 (PST) Received: from [127.0.0.1] (helo=softweyr.com ident=Fools trust ident!) by homer.softweyr.com with esmtp (Exim 3.16 #1) id 140ROt-00008R-00; Mon, 27 Nov 2000 09:45:08 -0700 Message-ID: <3A228F93.40812671@softweyr.com> Date: Mon, 27 Nov 2000 09:45:07 -0700 From: Wes Peters Organization: Softweyr LLC X-Mailer: Mozilla 4.75 [en] (X11; U; Linux 2.2.12 i386) X-Accept-Language: en MIME-Version: 1.0 To: Andrew Otwell Cc: hackers@freebsd.org Subject: Re: porting Linux application to FreeBSD References: <3A228681.4A3DBE88@iss.net> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Andrew Otwell wrote: > > source.c > ------------------------- > #include > int main () { > printf ("Hello world\n"); > } > ------------------------- > > A couple of you answered my first query which gave me.... > > gcc -nostdinc -I/includedir -nostdlib -L/libdir source.c > > This always failed with either.... > > ld: No reference to __DYNAMIC > collect2: ld returned 1 exit status > > or > > /var/tmp/ccdgopIG.o: Undefined symbol `___main' referenced from text segment > /var/tmp/ccdgopIG.o: Undefined symbol `_printf' referenced from text segment > /var/tmp/ccdgopIG.o: Undefined symbol `_printf' referenced from text segment > collect2: ld returned 1 exit status > > Depending on whether I specified lib names (ex. -lnet -lpcap -lgcc, etc....) > > I finally pulled all my hair out and ran > > gcc -nostdinc -I/usr/include -nostdlib -L/usr/lib source.c > =-= and =-= > gcc -nostdlib -L/usr/lib source.c > > and again I received..... > /var/tmp/ccdgopIG.o: Undefined symbol `___main' referenced from text segment > /var/tmp/ccdgopIG.o: Undefined symbol `_printf' referenced from text segment > /var/tmp/ccdgopIG.o: Undefined symbol `_printf' referenced from text segment > collect2: ld returned 1 exit status > > Can anyone assist with this? > I need to be able to compile and link a "Hello World" program against a > proprietary > lib dir for my project but for starters I have to make sure my anomolies are not > with the "ld" portion of my build. > > Why doesn't "gcc -nostdlib -L/usr/lib source.c" link properly? I even added > all the .a files with -lnet -lpcap -ledit, so forth.... and it still failed. Because you told it not to link with the standard libraries. You will have to provide a library with a printf function, and a C runtime startup function with at least the functionality of the standard FreeBSD one. If you are trying to build a completely static image for an embedded system or something like that, you might want to install a GCC cross-compiler and binutils. See, for instance, in /usr/ports/devel: *-rtems-binutils *-rtems-gcc etc. -- "Where am I, and what am I doing in this handbasket?" Wes Peters Softweyr LLC wes@softweyr.com http://softweyr.com/ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message