Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Shared object creation: dangling symlink using make

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

$ 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?

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading