I have an executable that linked with shared library 'A' , which in turn uses shared library 'B' (GUI written in Qt). When i compile the executable, the linker looks for all the libraries, including 'B', and all libraries it needs inside (Qt libraries). How can i disconnect the 'B' library from the executable in such way that it will not need the 'B' in the link time. I'd like that the executable will not know about the 'B' library.
-
3Why? How will your executable run if it doesn't have its dependencies present? – John Zwinck Dec 30 '14 at 08:27
-
Make A load B at runtime or load A at runtime. This would make you application a lot more complex and error prone, but would work. – UldisK Dec 30 '14 at 10:25
-
Your question is not clear at all. "the linker looks for all the libraries including B": it checks that A's dependencies are present, but it shouldn't link with B directly, so if you replace A with a version that doesn't use B, it will still be fine and not use B. You could provide a fake version of A with the same list of (empty) symbols, just for linking. – Marc Glisse Dec 30 '14 at 11:12
-
The solution i found working is to load B dynamically in A by dlopen. In this way the executable doesn't have to know about B. – Alex Dec 30 '14 at 12:39
1 Answers
Assuming you can build dependency 'B' from source, you can hide it from your executable by linking 'A' statically to 'B'.
In the case of not being able to compile 'B' from source, it's possible to limit visibility of symbols in 'B' that are not explicitly used. You can accomplish this via the 'ld' command on Unix systems. I know very little about this. This post may offer some suggestions. However, they strike me as very explicit and manual, so probably less applicable if 'B' is a large library with many symbols. I suspect that's not really what you were going for.
You want 'B' to not show up when calling the 'ldd' command on your executable. Is that right?
Or are you only trying to make the installation of your executable easier on users? If yes, you can still automate the installation to some extent.
-
My goal is the ability to compile and run the executable only with A object without B on the machines where the UI is not necessary and Qt is not installed. – Alex Jan 01 '15 at 15:41