[Expat-discuss] makefile to use expat
Dan Nicholson
dbn.lists at gmail.com
Mon Feb 18 21:51:04 CET 2008
On Feb 18, 2008 12:32 PM, Jun Cao <caoj at purdue.edu> wrote:
> I use the following makefile:
>
> CC = gcc
>
> GSL_LIB = -L/opt/osg/expat/lib
This should be two parts since you're not actually passing the library
to link to:
GSL_LDFLAGS = -L/opt/osg/expat/lib
GSL_LIB = -lexpat
> GSL_INC = -I/opt/osg/expat/include
>
> LIBS = ${GSL_LIB} -lexpat
LIBS = $(GSL_LIB)
> CFLAGS = ${GSL_INC}
LDFLAGS = $(GSL_LDFLAGS)
> OBJS = model.o
>
> all: ${OBJS} project
>
> project: ${OBJS}
> ${CC} -o $@ ${OBJS} ${LIBS}
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
> run:
> ./project
>
> I pass the compilation, but I got the folllowing error:
> -bash-3.00$ ./project
> ./project: error while loading shared libraries: libexpat.so.1: cannot open
> shared object file: No such file or directory
Here the problem is that the dynamic linker doesn't know to look in
/opt/osg/expat/lib at runtime. You can set the environment variable
LD_LIBRARY_PATH:
export LD_LIBRARY_PATH=/opt/osg/expat/lib
./project
or encode the path into the executable by setting a rpath. There are
various ways to do this, but the way to do this with the GNU linker is
the -rpath switch:
GSL_LDFLAGS = -L/opt/osg/expat/lib -Wl,-rpath,/opt/osg/expat/lib
Then the runtime linker will always look in that directory first for
any libraries the project program needs. You can then see the path in
the executable by using readelf:
readelf -d project | grep RPATH
--
Dan
More information about the Expat-discuss
mailing list