i did these steps and make shared library.
but here i have some questions
-
i want know why we write 4 and 5 steps.
i know only that these steps is used for link library
-
in 6th step why we use only lhuffman insted of libhuffman
steps:
1 gcc -c -fPIC filebits.c -o filebits.o
2 gcc -shared -Wl,-soname,libhuff.so.1 -o libhuffman.so.1.0.1 filebits.o
3 mv libhuffman.so.1.0.1 /home/mydesktop/slib/
4 ln -sf /home/mydesktop/slib/libhuffman.so.1.0.1 /home/mydesktop/slib/libhuffman.so
5 ln -sf /home/mydesktop/slib/libhuffman.so.1.0.1 /home/mydesktop/slib/libhuffman.so.1
6 gcc -o app app.c -lhuffman
7 ./app
please explain me these steps
In step 4 you are creating a soft link to the library name which is looked up by the linker to link.
In step 5 you are creating a soft link to the library indicating its major version. There is no need for you to follow these steps as such instead you can generate
libhuffman.soas the output in the first step which is what the linker looks up for. But this convention is followed so that library’s major & minor versions are tracked easily. Generally, library has the name aslibrary_name.MAJOR_VERSION.MINOR_VERSION. There is soft link to that in the form oflibrary_name.MAJOR_VERSION& another soft link with justlibrary_name.library_nameis in the form of lib[library_name].so as that is format expected by the linker when using-loption. You can check libraries on your Linux PC you will see this convention being followed in a lot of cases. This link provides some details regarding this.GCC linker adds lib & .a (or .so) to the library name which is specified with
-loption.Hope this helps!