'How to build a standalone C ELF binary without installing libraries on a remote machine?

I am trying to build a C ELF binary on linux and try to execute it directly on another machine. (Sent via scp linux command)

The problem is that even when I build the ELF binary with all needed libs, when I try to execute it on the remote machine, I got this error:

/tmp/25636: error while loading shared libraries: libnftnl.so.11: cannot open shared object file: No such file or directory

Since I can't execute sudo apt install -y libfuse-dev libmnl-dev libnftnl-dev to install my libs on the remote machine , I wanted to know if it was possible to package all the dependancies within the ELF binary, so that the ELF binary can be executed in a standalone way.

enter image description here

bguess.



Solution 1:[1]

@????? was right. adding the -static flag works, but the thing is that you have to add it at the right place !

For me it was right after the -o OUTPUT_FILE and before CFLAGS and LDFLAGS.

Thank you all for your help.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1