Adding the path to the shared library in the Makefile

I want to add the path to the shared library in my Makefile. I entered the export command in the make file, it is even called, but I still have to manually export it again. What is the right approach?

Makefile:

SOURCES = kwest_main.c fusefunc.c dbfuse.c logging.c dbbasic.c dbinit.c dbkey.c metadata_extract.c plugins_extraction.c import.c LIBS = -L$(LIB) -lfuse -lsqlite3 -lkw_taglib -ltag_c -ltag -Wl,-rpath=. INCLUDE = ../include LIB = ../lib EXE = kwest CC = gcc CCFLAGS = -g -Wall -Wextra -std=gnu99 -pedantic-errors -I$(INCLUDE) OFLAGS = -c ARCH = $(shell getconf LONG_BIT) X = -D_FILE_OFFSET_BITS=$(ARCH) OBJECTS = $(SOURCES:.c=.o) $(EXE) : $(OBJECTS) $(CC) -o $(EXE) $(OBJECTS) $(LIBS) %.o: %.c $(CC) $(OFLAGS) $(CCFLAGS) $< fusefunc.o: fusefunc.c $(CC) $(OFLAGS) $(CCFLAGS) $< $X kwest_libs: kw_taglib --->export LD_LIBRARY_PATH=$(LIB):$LD_LIBRARY_PATH kw_taglib: plugin_taglib plugin_taglib: plugin_taglib.o kwt_upd_meta.o gcc -g -shared -I$(INCLUDE) -Wl,-soname,libkw_taglib.so -o $(LIB)/libkw_taglib.so -ltag -ltag_c plugin_taglib.o kwt_upd_meta.o plugin_taglib.o: gcc -c -g -I$(INCLUDE) -Wall -Wextra -pedantic-errors -std=gnu99 -fPIC -ltag_c -c plugin_taglib.c kwt_upd_meta.o: g++ -c -g -I$(INCLUDE) -Wall -Wextra -pedantic-errors -fPIC -ltag kwt_upd_meta.cpp c: clean clean: rm -rf *.o rm -rf *.db ca: cleanall cleanall: clean rm -rf $(EXE) ob: cleanall rm -rf ~/.config/$(EXE)/ 

Execution:

 $ ./kwest mnt ./kwest: error while loading shared libraries: libkw_taglib.so: cannot open shared object file: No such file or directory $ export LD_LIBRARY_PATH=../lib:D_LIBRARY_PATH $ ./kwest mnt "executes correctly" 
+6
source share
2 answers

The usual way is to copy the dynamic library during creation by default and to one of the standard library paths

/ usr / local / bin

or one of the paths of your project library and add the library to the executable using

-L / project / specific / path

during make install.

+2
source

As mentioned here , what you probably want is the -rpath linker -rpath .

This way you can set the default search path for the binary. It looks like you are already using -rpath in your makefile, but you specified the wrong path:

 LIBS = -L$(LIB) -lfuse -lsqlite3 -lkw_taglib -ltag_c -ltag -Wl,-rpath=. 

Thus, the binary will be searched in the current directory for dyn libraries. However, you add ../lib to your LD_LIBRARY_PATH later to execute the binary, so this is the path . seems wrong.

Please try the following fix:

 LIBS = -L$(LIB) -lfuse -lsqlite3 -lkw_taglib -ltag_c -ltag -Wl,-rpath=../lib 

For this you do not need to specify LD_LIBRARY_PATH to execute.

+1
source

All Articles