Date: Wed, 04 Feb 1998 09:13:47 -0800 From: John Polstra <jdp@polstra.com> To: xavier@stlnet.com Cc: hackers@FreeBSD.ORG Subject: Re: Problems linking shared libraries with ld Message-ID: <199802041713.JAA03080@austin.polstra.com> In-Reply-To: <34D76A00.3F9F4818@stlnet.com> References: <34D76A00.3F9F4818@stlnet.com>
next in thread | previous in thread | raw e-mail | index | archive | help
In article <34D76A00.3F9F4818@stlnet.com>, Jon E. Kump <xavier@stlnet.com> wrote: > I am writing some code that I am linking in 11 shared libraries and one > static library. When ld goes to link the code I get an error from ld. > > ld: No reference to __DYNAMIC > > This is my make file that i am using. This program is a little 20 line > example. > > CC = gcc > CFLAGS = -g -funroll-loops -Wall -pipe -ansi > LDFLAGS = -Bdynamic > CPPFLAGS = > INCLUDES = -I. -I/usr/X11R6/include -I/usr/local/include > LIBDIR = -L/usr/X11R6/lib -L/usr/local/lib > LIBS = -lXm -lXpm -lXmu -lXt -lXext -lX11 -lXmHTML -lSM -lICE -ljpeg > -lpng -lz -lm > LOADLIBES = $(LIBDIR) $(LIBS) > > OBJS = autosize_html.o > > all: $(OBJS) autosize_html > > autosize_html.o: autosize_html.c > $(CC) $(CFLAGS) $(CPPFLAGS) $(INCLUDES) -c $< > > autosize_html: $(OBJS) > ld $(LDFLAGS) $(LOADLIBES) -o autosize_html $(OBJS) There are several problems with this makefile. First, all of your libraries must be listed at the _end_ of the linker command, i.e., _after_ all of the object files. Otherwise, the libraries will ignored, more or less. Second, all dynamic executables have to be linked with "/usr/lib/crt0.o" as the very first object file. The fact that you didn't do that is the source of the "No reference to __DYNAMIC" diagnostic. But the real problem is that you shouldn't be using "ld" directly for linking. Use "cc" instead, like this: $(CC) -o autosize_html $(OBJS) $(LDFLAGS) $(LOADLIBES) The exact command for linking an executable is different on practically every platform in existence. The "cc" command knows the idiosyncrasies of your platform, and it does the right thing. It's a much more portable way to build programs than using "ld" directly. John -- John Polstra jdp@polstra.com John D. Polstra & Co., Inc. Seattle, Washington USA "Self-knowledge is always bad news." -- John Barth
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199802041713.JAA03080>