adding shared library path to Makefile
The usual way is to copy the dynamic library during the default make and to one of the standard library path
/usr/local/bin
or one of your project library path and add the library to executable using
-L/project/specific/path
during make install.
Setting path to shared library inside a makefile for compile
Where I'm wrong ?
You are wrong in that you modified your Makefile
incorrectly.
You have a macro Q
, which evaluates to @
, which makes the make
quiet (not print the command it executes) if @
is the first character of the command line. By prepending LD_LIBRARY_PATH
to the command line, you screwed that up:
# this is a quiet command:
@ar ...
# this is a not quiet command, which tries to execute @ar, which doesn't exist:
LD_LIBRARY_PATH=... ; @ar ...
The second part of wrong is that setting LD_LIBRARY_PATH
as you did only affects the building of the libraries (i.e. the compiler and the linker). What you want is to affect the runtime using these libraries, not the compiler and linker used to build them.
As DevSolar correctly stated, you want -rpath
instead:
$(Q)$(CC) $(SOFLAGS) -o $@ $(MINIZIP_DIR)/ioapi.so \
-Wl,-rpath=$(ZLIBDIR) $(MINIZIP_DIR)/zip.so ...
Setting path to shared library inside a makefile for execution
Each line in a recipe is run in its own shell, so change it to:
run:
export LD_LIBRARY_PATH=$(TESTLIB):$(DEPENDENCIES); \
./testit
or
run:
LD_LIBRARY_PATH=$(TESTLIB):$(DEPENDENCIES) ./testit
Change search path for shared library to rpath provided in Makefile
I have transferred libB.so.1.0 to my local lib-folder and linked the application against it using rpath. However, this path is not used to find libB.so.1.0 for libA.so(but the rpath is used for other shared-libraries that are linked directly).
That is the expected behavior when the application has RUNPATH
(which is the newer default when -rpath
is specified at link time).
You want the "recursive" behavior of RPATH
instead. Documentation explaining the difference.
Step 1: confirm that your app is indeed using RUNPATH
:
readelf -d a.out | egrep 'RPATH|RUNPATH'
Step 2: use -rpath=... -Wl,--disable-new-dtags
to link your application, and confirm that RPATH
is now being used.
Step 3: confirm that libB.so.1.0
is now found.
Enjoy :-)
Related Topics
Clearing Large Apache Domain Logs
Linux Module to Hook Process Functions
Alpine Linux: Pmap Output Not Showing Rss
Graphics Card Memory Usage in Linux
How to Do "For Each" on Output from Find
How My Custom Module on Linux 3.2.28 Can Make a Call to Print_Cpu_Info
Editing The Sudo File in a Shell Script
Pid File Exists, But Process Is Not Running
Udp Server Giving Segmentation Fault
How to Check If a UId Exists in an Acl in Linux
Getting Root Privileges in Ansible
File Search Algorithms Using Indexing in Linux
Is There Compatible Odbc Driver with Mariadb 10 on Linux
Linux: Changing File Ownership Without a Copy
Cannot Push to My Github Private Repository
Azure Cli Aks Install Cli Permission Denied and Sudo Does Not Work
What Does Signal(Sigchld, Sig_Dfl); Mean
How to Determine The Date-And-Time That a Linux Process Was Started