linux - Setting path to shared library inside a makefile for compile -


i want compile program using makefile linked against zlib shared libraries different 1 installed on system. don't want them permanently added library pool of system.

the path of custom zlib /usr/work/libxlsxwriter-master/zlib-1.2.8

i have tried use like:

zlibdir=/usr/work/libxlsxwriter-master/zlib-1.2.8  # static library. $(libxlsxwriter_a) : $(objs)     export ld_library_path=$(zlibdir):$(dependencies); \     $(q)$(ar) $(arflags)     $@ $(minizip_dir)/ioapi.o $(minizip_dir)/zip.o  $^   # dynamic library.  $(libxlsxwriter_so) : $(sobjs)     export ld_library_path=$(zlibdir):$(dependencies); \     $(q)$(cc) $(soflags)  -o $@ $(minizip_dir)/ioapi.so $(minizip_dir)/zip.so $^ -lz  # targets object files. %.o  : %.c $(hdrs)     $(q)$(cc)       -i$(inc_dir) $(cflags) $(cxxflags) -c $<   %.so : %.c $(hdrs)     $(q)$(cc) -fpic -i$(inc_dir) $(cflags) $(cxxflags) -c $< -o $@    %.to : %.c $(hdrs)     $(q)$(cc) -g -o0 -dtesting -i$(inc_dir) $(cflags) $(cxxflags) -c $< -o $@ 

when try compile, have error : /bin/sh: line 1: @ar: command not found

where i'm wrong ?

where i'm wrong ?

you wrong in modified makefile incorrectly.

you have macro q, evaluates @, makes make quiet (not print command executes) if @ first character of command line. prepending ld_library_path command line, screwed up:

# quiet command: @ar ...  # not quiet command, tries execute @ar, doesn't exist: ld_library_path=... ; @ar ... 

the second part of wrong setting ld_library_path did affects building of libraries (i.e. compiler , linker). want affect runtime using these libraries, not compiler , linker used build them.

as devsolar correctly stated, want -rpath instead:

$(q)$(cc) $(soflags) -o $@ $(minizip_dir)/ioapi.so \   -wl,-rpath=$(zlibdir) $(minizip_dir)/zip.so ... 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -