I created a shared library (e.g. libabc.so) and an executable (i.e. myapp) that uses my shared library. I put both the shared library and my executable in my file system, but when I ran my executable, it gave me the following error:
when loading shared libraries: /. so cannot open the shared objects file: there is no such file or directory.
Now my development environment is - I have another target file system that is placed in (~ / targetfs) after creating my shared library, which I install in (~ / targetfs / usr / local / abc / lib). While linking my application I give it
LDFLAGS + = -L ~ / targetfs / usr / local / abc / lib
My application is building perfectly. But when I run my application in an environment where (~ / targetfs) is my file system, my application complains about error while loading shared libraries: /home/user/targetfs/usr/local/abc/lib/libabc.so: impossible open the file of shared objects. There is no such file or directory.
Now, of course, the way in which my application searches for a shared library that does not exist, but I want my application not to depend on this path, rather, it should look for my shared library in / lib, / usr / lib, / usr / local / lib or LD_LIBRARY_PATH.
So the question is: "How can I get my application to link libraries regardless of their location?"
The makefiles for my shared library and application are listed below.
-------------- General archive file. (Omitting unnecessary information)
CC = $(CROSS_COMPILE)gcc CFLAGS = -Wall -shared -fpic LDFLAGS = -Xlinker --gc-sections --allow-shlib-undefined LIBRARY = libabc.so OBJ_DIR = obj SRC_DIR = src CHK_DIR_EXISTS = test -d MKDIR = mkdir -p # Project Source Files C_SOURCES += $(SRC_DIR)/abc.c OBJECTS += $(OBJ_DIR)/abc.o INCLUDES += -Iinc $(LIBRARY): $(OBJECTS) @echo "" @echo "Linking..." $(LIBRARY) @$(CC) $(CFLAGS) $(LDFLAGS) $(OBJECTS) -o $(OBJ_DIR)/$(LIBRARY)
---------- Application Makefile (Omitting unnecessary information)
LDFLAGS += $(TARGETFS)/usr/local/abc/lib/libabc.so \ -lpthread -lrt
Any thoughts that are missing in my makefiles.
Regards, Farrukh Arshad