I am trying to create a shared library using gcc
and make
. I have the following section in the Makefile to compile the shared library object:
# The library build step.
lib : $(DHLLOBJS)
$(CC) $(XCFLAGS) $(SCFLAGS)$(SLIB).1 $(INCFLAGS) -o $(LIB_DIR)/$(SLIB).1.0 \
$(DLOPATHS) $(LNKFLAGS)
ln -sf $(LIB_DIR)/$(SLIB).1.0 $(LIB_DIR)/$(SLIB).1
ln -sf $(LIB_DIR)/$(SLIB).1.0 $(LIB_DIR)/$(SLIB)
The above doesn't throw any compilation errors or file system errors but the symlinks are described as dangling
as shown by a chmod
command:
$ sudo chmod 0755 ../lib/*
chmod: cannot operate on dangling symlink '../lib/libdhlim.so'
chmod: cannot operate on dangling symlink '../lib/libdhlim.so.1'
and the ls
command output below shows the lines 5 and 6 in red:
$ ls -la lib/
total 29
drwxrwxrwx 1 root root 376 Jul 5 21:13 .
drwxrwxrwx 1 root root 4096 Jul 5 21:13 ..
lrwxrwxrwx 1 root root 21 Jul 5 21:13 libdhlim.so -> ./lib/libdhlim.so.1.0
lrwxrwxrwx 1 root root 21 Jul 5 21:13 libdhlim.so.1 -> ./lib/libdhlim.so.1.0
-rwxrwxrwx 1 root root 23792 Jul 5 21:13 libdhlim.so.1.0
When I run the same set of commands manually, they work fine. Is there something I am doing wrong here?
CodePudding user response:
The problem is that you use relative paths but don't create the links with the ln
option -r
.
Try these as the last two lines:
ln -sfr $(LIB_DIR)/$(SLIB).1.0 $(LIB_DIR)/$(SLIB).1
ln -sfr $(LIB_DIR)/$(SLIB).1.0 $(LIB_DIR)/$(SLIB)
-r, --relative
with -s, create links relative to link location