The compiling worked after:
It seems I'm getting closer to the point now. The shared library libhts.so.3 is located in ${LIBROOT}.
I did not mean to be lazy without digging the ld_config(?) or related subjects, but simply to stay consistent with this same example to avoid confusion.
How to ensure the dynamic library is available for the new executable vcf_parser01 just compiled?
Thanks!
Last edited by yifangt; 01-15-2020 at 06:40 PM..
Reason: adding now info
If you link to a shared library intead of the archive it's a little more complicted. If the shared library isn't installed in a directory know to the loader then you need to tell it where to find it. The rpath option I mentioned is passed to the linker and added to the executable. As long as the shared library is in the same place it will find it. You can also set LD_LIBRARY_PATH to the directory where it is. One way to do this (in a bash shell) is:
If you link to a shared library intead of the archive it's a little more complicated.
Thank you for point that out. Actually I meant the archive here.
I happened to found this articleusing a special variable $ORIGIN, and that seems to make everything working now.
But, I could not find the reference in the GCC manual about this variable, or the -rpath. I am not sure if this is the correct way to do the job.
Especially, what's the standard way?
Thank you very much again.
Last edited by yifangt; 01-17-2020 at 12:58 PM..
Reason: correct format & indentation
rpath is actually a linker option rather then a compiler option. gcc passes it to ld.
Well, th estandard way to use shared objects (.so) is to install them in the system directories used for that purpose (/usr/lib etc.) but that's not always possible. The archive (.a) allows you to link objects into your executable which produces a larger exectable but gets around the problem. If the library is updated you must recompile whereas with a shared object you only need to recompile if the update breaks your code.
For the loader to load a shared object at runtime it must know where to find them. rpath tells the linker to embed the path in the header of the executable but if the so is moved the loader won't be able to load it. ORIGIN resolves to whereeve the binary is at runtime so as long as the library stays with the executable it works.
Thanks Greg, and Neo---although your input is more than I expected.
I found the topic deviated from the original point I was asking, because there are many aspects hidden behind my question that I do not know. However, It is easier for me to learn by example, especially on coding.
Normally, I found there is one layer missing to me when others library is installed in the system. Simply sudo apt-get install / sudo yum install etc does not help me in actual C coding from scratch.
Here, I want to stick to the tech and only the tech part, i.e: "In my this example, what is the correct/standard way to make use the downloaded htslib not installed system-wide? "
1) I want to confirm the options of my command line that are correct in general, while I'm trying to find the official reference (which normally do not have real hands-on example, e.g $ORIGIN);
2) Trying to catch the standard way to use non-system *.a and *.so files in C coding on top of point 1). Here "standard way" can be replaced with "common way" if there is not all-for-one solution, which is normally the case.
Two examples, (1) the standard way to use shared objects (.so) is to install them in the system directories Thanks Greg! This cleared my confusion. The not-answered part is how to make use of the *.so file when it is not installed system wide. (2) I saw people usually use static library for *.a filesand dynamic library for *.so files, but Greg consistently use archives for *.afiles and shared objects for *.so ones. It seems to me that they are different names for the same thing, but I might be wrong. This was a so big confusing wording! And I owe an apology to all who read this post!
3) My point is what the right way(s)---may not be the best way--- is to use them.
Can I ask in another way:
What is the best practice to use others library (static*.a and shared*.so) not installed system-wide in C programming? I may need to start a new thread before the topic is veered too far off.
It seems to me that they are different names for the same thing, but I might be wrong.
3) My point is what the right way(s)---may not be the best way--- is to use them.
Can I ask in another way:
What is the best practice to use others library (static*.a and shared*.so) not installed system-wide in C programming? I may need to start a new thread before the topic is veered too far off.
Thank you so much for your time!
No, they are not at all the same thing. An archive is just that. A collection of object files that can be statically linked to your executable. Shared objects are dynamically linked at runtime. They are compiled with a flag that tells the compiler to generate position independent code. Here's what gcc docs have to say:
Since archives are statically linked to your your code, it is no longer dependent on the object. With shared objects you remain dependent on the library.
When looking for wherever a program or a filename appears in the system, a short scrip is "findinner" which another script calls with a long parameter list consisting of path names ending with ".sh" or ".menu". "findinner" looks like this:
# If not .savenn file, show name and result of grep.
#... (4 Replies)
I have installed user-mode linux kernel in Ubuntu 10.10 with the help of Synaptic package manager.
But I'm not getting how to run it.
If we install it manually, we've to run it using the executable binary file.
But here, I'm unable to locate any such file.
Please help....
Thanking You....
... (0 Replies)
Hi,
I need to look for a config file (ldap.conf) and pick the latest modified file.
`locate` tells me there are many ldap.conf's, some in /etc, /usr, /home, etc.
Is there some way I can sort them by last modified time via bash?
I was thinking maybe I could pipe the output of `locate` to `ls... (4 Replies)
Hello,
I am new to shell scripting and I was trying to write a script that would force a system wide password change except for admins. I am having some trouble and any help that someone could give me would be greatly appreciated. I am trying to do it by using the UID as the marker for anyone... (6 Replies)
Yea i was wondering how i would mount, and create a FAT directory that way i can save files in the FAT directory in a windows system and be able to access them on Linux systems. Or if there is any other way to share files between Linux and Windows. Any responds will help... thanks! (2 Replies)
Hi, I have a task to search for a file called 'Xstartup' in the whole system because there might be different versions of it which overrite eachother.
Can anyone suggest a smart command to run this search ? The machine needs to scan every single folder beginning from root.
Please help, I am... (5 Replies)
I have created symbolic links to several frequently used commands, for example:
"lt" is a link to "ls -ltrgo|tail". What can I do to make these links available system-wide, or at least in the directories my coworkers are in most of the time? I have copied the link to several directories, and... (6 Replies)