How do I prevent hard coded library path dependencies in my executables created with gcc ?
Posted on 2004-04-22
My make file links the executable with shared libraries. I have set the library search path with the "-L..\lib\x86_64". The resultant executable then has hard coded dependency to ..\lib\x86_64 which I do not want. When program loads, I want LD_LIBRARY_PATH to determine which shared library to link with - I do not want it hard coded.
Below is my make file for tgoctest executable. Along with a "strings" output which proves that the executable is hard wired to a specific path.
PROJ = tgoctest
CC = gcc
LINK = gcc
#default configuation - this should be speciifed when using this makefile
#default platform - this should be specified when using this makefile
LIBS_EXT = -lpthread -lncurses
CFLAGSDEBUG = -g -D "_DEBUG" -D "UNIX" -D "LINUX" -I ../include
LFLAGSDEBUG = -g -L../lib/$(TGPLATFORM) -ltgoc -ltgjpeg
CFLAGSRELEASE = -O -D "UNIX" -D "LINUX" -I ../include
LFLAGSRELEASE = -L../lib/$(TGPLATFORM) -ltgoc -ltgjpeg
TGOCTEST_DEP = ../include/tgocosdp.h \
all: checkconfig $(OBJDIR)/$(PROJ)
@if [[ ! -d $(OBJDIR) ]]; then \
mkdir $(OBJDIR); \
"tgoctestlinux.mak" 50L, 1116C
tyohe@suse64:/yam/tg/source/tgoctest> strings x86_64/tgoctest | grep lib
Zlib Compile Flags =0x%x
Set Zlib compression level