digitalmars.D.learn - Dynamically calling shared objects from statically build executable
- Andre Pany (22/22) Feb 09 2020 Hi,
- Ernesto Castellotti (9/12) Feb 10 2020 On Unix systems it is not possible to dynamically load a library
- Andre Pany (13/25) Feb 10 2020 This is a topic I almost have no knowledge, therefore a question.
- Ernesto Castellotti (7/36) Feb 10 2020 Static libraries are simple collections of object files, there is
- Andre Pany (5/13) Feb 11 2020 Thanks for the explanation.
Hi, while dynamically calling a shared object from a statically build executable on linux, both LDC and DMD fails with a non-zero code 139. In my productive system the SO is written in C++, for reproduction I wrote a sample SO in D. You can find the example here https://github.com/ldc-developers/ldc/issues/3310 Is this a bug with LDC and DMD, or is it not allowed to dynamically call a SO from a statically build executable on linux? Background: The SO file I get from third party, while the executable I develop. I need to run the executable on a distroless docker image (SCRATCH), therefore I try to reduce system dependencies on my side by building a static executable. PS. DMD even fails without the static switch with: Aborting from src/rt/sections_elf_shared.d(480) DSO being unregistered isn't current last one. Kind regards André
Feb 09 2020
On Monday, 10 February 2020 at 04:41:31 UTC, Andre Pany wrote:Is this a bug with LDC and DMD, or is it not allowed to dynamically call a SO from a statically build executable on linuxOn Unix systems it is not possible to dynamically load a library shared by a static executable, I don't know if it works differently for Windows. This is because it is absolutely necessary to link libdl dynamically, you cannot link static. For GNU/Linux systems there is this alternative to dlopen/dlsym that does not require dynamic link: https://www.gnu.org/software/libtool/manual/html_node/Dlpreopening.html
Feb 10 2020
On Monday, 10 February 2020 at 13:14:50 UTC, Ernesto Castellotti wrote:On Monday, 10 February 2020 at 04:41:31 UTC, Andre Pany wrote:This is a topic I almost have no knowledge, therefore a question. If I understand this StackOverflow question correctly, it is possible to call dynamically a shared object from a static library (with dlopen): https://stackoverflow.com/questions/17862272/dlopen-a-dynamic-library-from-a-static-library-linux-c But I understand from you it is not possible dynamically call a shared object from a static executable. Therefore it works for static libraries but not for statically executables? Kind regards AndreIs this a bug with LDC and DMD, or is it not allowed to dynamically call a SO from a statically build executable on linuxOn Unix systems it is not possible to dynamically load a library shared by a static executable, I don't know if it works differently for Windows. This is because it is absolutely necessary to link libdl dynamically, you cannot link static. For GNU/Linux systems there is this alternative to dlopen/dlsym that does not require dynamic link: https://www.gnu.org/software/libtool/manual/html_node/Dlpreopening.html
Feb 10 2020
On Monday, 10 February 2020 at 19:00:36 UTC, Andre Pany wrote:On Monday, 10 February 2020 at 13:14:50 UTC, Ernesto Castellotti wrote:Static libraries are simple collections of object files, there is no difference between linking a static library or several object files If you notice when going to compile the executable linka libdl and the static library, then the executable will be linked to dynamic library and will not be a static executable.On Monday, 10 February 2020 at 04:41:31 UTC, Andre Pany wrote:This is a topic I almost have no knowledge, therefore a question. If I understand this StackOverflow question correctly, it is possible to call dynamically a shared object from a static library (with dlopen): https://stackoverflow.com/questions/17862272/dlopen-a-dynamic-library-from-a-static-library-linux-c But I understand from you it is not possible dynamically call a shared object from a static executable. Therefore it works for static libraries but not for statically executables? Kind regards AndreIs this a bug with LDC and DMD, or is it not allowed to dynamically call a SO from a statically build executable on linuxOn Unix systems it is not possible to dynamically load a library shared by a static executable, I don't know if it works differently for Windows. This is because it is absolutely necessary to link libdl dynamically, you cannot link static. For GNU/Linux systems there is this alternative to dlopen/dlsym that does not require dynamic link: https://www.gnu.org/software/libtool/manual/html_node/Dlpreopening.html
Feb 10 2020
On Monday, 10 February 2020 at 19:39:04 UTC, Ernesto Castellotti wrote:On Monday, 10 February 2020 at 19:00:36 UTC, Andre Pany wrote:Thanks for the explanation. Kind regards André[...]Static libraries are simple collections of object files, there is no difference between linking a static library or several object files If you notice when going to compile the executable linka libdl and the static library, then the executable will be linked to dynamic library and will not be a static executable.
Feb 11 2020