Reputation: 97
In a project I have an already created shared library called, let's say, 'myshare'. The library is already created as 'libmyshare.so.1.0.0' and its location is relative to the makefile at a relative address of 'adir/lib'.
In the makefile I want to create symbolic links for the shared library with the names 'libmyshare.so.1' and 'libmyshare.so'. In order to do this in the makefile I have these lines:
MYSHAREL = ./adir/lib/libmyshare.so.1.0.0
MYSHAREL1 = ./adir/lib/libmyshare.so.1
MYSHAREL2 = ./adir/lib/libmyshare.so
MYSHARELIBS = $(MYSHAREL) $(MYSHAREL1) $(MYSHAREL2)
.PHONY: all
all: myexetarget
myexetarget : various_files $(MYSHARELIBS)
various_commands_to_make_target
$(MYSHAREL1): $(MYSHAREL)
@echo "Creating symbolic link $(MYSHAREL1)"
@ln -s $(MYSHAREL) $(MYSHAREL1)
$(MYSHAREL2): $(MYSHAREL)
@echo "Creating symbolic link $(MYSHAREL2)"
@ln -s $(MYSHAREL) $(MYSHAREL2)
When I run the 'make' command the links to the shared library are always created even when they already exist and even when the date of the shared library is prior to the date of already created symbolic links. Furthermore when I try to actually link to the shared library in my target, despite an -L./adir/lib
and -lmyshare
options among the linker options ( not shown above ) the link fails with:
/usr/bin/ld: cannot find -lmyshare
Both these problems lead me to believe that I am not specifying the name or relative location of the shared library correctly for the makefile processing to understand it. Does anybody know what I am doing wrong ?
Upvotes: 0
Views: 799
Reputation: 29040
Your use of ln -s
is probably the cause of your problem. If, from your top directory you execute:
ln -s ./adir/lib/libmyshare.so.1.0.0 ./adir/lib/libmyshare.so.1
(which is what your make rule does) a symbolic link is created in ./adir/lib
, named libmyshare.so.1
and pointing to ./adir/lib/libmyshare.so.1.0.0
:
$ cd ./adir/lib
$ ls -l
libmyshare.so.1 -> ./adir/lib/libmyshare.so.1.0.0
libmyshare.so.1.0.0
So, ./adir/lib/libmyshare.so.1
actually points to ./adir/lib/adir/lib/libmyshare.so.1.0.0
that does not exist.
You can replace your ln -s
command by:
@ln -sr $(MYSHAREL) $(MYSHAREL1)
Same for MYSHAREL2
. The -r
option of ln
create symbolic links relative to link location.
Upvotes: 1