How does one run a standalone executable built on another Linux platform, so that all libraries and dependencies are taken from the build system and not the host?
-
If I copy the executable from the build node, I need at least to include all library dependencies when I run it on the host node. And then I modify LD_LIBRARY_PATH to ensure that the dependent libraries are seen. However, library versions (between the build and host nodes) may be different in the case of duplicates, so I may need to do an LD_PRELOAD to ensure that the host sees the library copied from the build node instead. Furthermore, glibc and ld-linux may be different, so this requires running the build node's version of ld-linux (where not only LD_PRELOAD includes glibc and system libraries, but also ld-linux is used to invoke the executable). I understand that this approach works (there may be tweaks or ideas I didn't mention, in which case comments are invited), and that proot or a type of chroot can be used to run the executable in an isolated way, but the challenge comes up when the build node's executable is to be run on the host, but at the same time descendant processes are to use the host's native environment. If I use the LD_LIBRARY_PATH approach, then descendant processes inherit that variable, which can interfere with the normal functionality of the host's binaries. Furthermore, using LD_PRELOAD makes this an even more likely situation, since LD_PRELOAD overrides the standard path. Also, LD_PRELOAD may pose a security risk. Finally, when using ld-linux to invoke the build node's binary and when also overriding the glibc for the desired process to be that of the build node, the problem becomes the most clear, because descendant processes are run using the build environment and with the ld-linux override, the native host binaries don't run. I don't know if there's a replacement environment variable I can pass to let new processes use a particular ld-linux. In that case, the original executable that was intended to be built on the build node and run on the host, if its source is available, can be modified to (re)set LD_PRELOAD and LD_LIBRARY_PATH to some ORIGINAL_LD_LIBRARY_PATH value for any subsequent spawned processes. It wouldn't be enough to cause descendant processes to be run transparently with the host system's ld-linux but it would be a start. A static binary is not always possible to create. Furthermore, solving this well can help in the case that a third party product is distributed for a particular Linux platform (its build host) that differs, even slightly, to that of the native host system. If software is released and is intended to run on a particular RedHat or Debian derivative, then the libraries and prerequisite environment components can be separately downloaded (updated to the latest stable/security patch) and then used to run the supplied executable. But the question is broader than this use case.
-
Answer:
You could use static compiling. Or using interpreted languages (with the needed libraries installed locally for your app). Go could be also a valid solution. Or you could use Docker containers to put with you app the entire filesystem it depends on, as long as Docker is available for the target systems.
Gustavo Muslera at Quora Visit the source
Other answers
As long as the target node can handle the instructions generated by the compiler on the compile node, you can use static linking to generate a self contained binary. ICC & GCC flag: -static If for example you compile the code with optimizations on an Intel processor with SSE 4.2 instructions, the compiler may choose to use those instructions in your binary. If you take this binary and attempt to run it on an older generation processor that does not support SSE 4.2 instructions, the executable cannot run and will fail with "Illegal Instruction" error. If you know that the target system has the needed standard libraries, you can minimize the size of your application by using other relevant flags like: For GCC: -nostartfiles -nodefaultlibs -nostdlib Full options here: http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html For other compilers like Intel or PGI, pelase refer to their manuals. Lastly, you may also want to make sure the target system running the code meets the minimum ABI requirements of the generated binary. You can read more about ABI and LSB efforts here: http://www.linuxfoundation.org/collaborate/workgroups/lsb
Kalyana Krishna Chadalavada
Related Q & A:
- How to know if a file has 'access' monitor in linux?Best solution by Unix and Linux
- How do I run a silent auction?Best solution by Yahoo! Answers
- How do you run a print head cleaning?Best solution by wikihow.com
- How do I run a fast mile?Best solution by Yahoo! Answers
- How do I run a game on both of my monitors?Best solution by tomshardware.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.