How to build a static nload binary ?
quaggalinux opened this issue · 5 comments
Hi,
Could you tell me how to build a static nload binary ?
Or, is there any parameters to make static nload binary ?
Thank you!
Hi! I had no success building this as a static binary using an ncurses
installed using the distro's package manager (neither on Debian, nor Manjaro), it seems that it lacks the static ncurses
library. But it was pretty straightforward when I built it myself.
You need to get the ncurses
source (https://github.com/mirror/ncurses this one seems up to date) and build it normally, the default option is to generate static libraries. Then you can point the nload
makefile to the newly built ncurses
libs and also add the -static
parameter to the linker.
CPPFLAGS=-I[path_to_ncurses]/include LDFLAGS="-L[path_to_ncurses]/lib -static" ./configure
make
This successfully built a statically linked binary.
@paunstefan ,
Thank you for your reply!
I followed your hints to compile the program, but ended up with a output binary runing error and report "Error opening terminal: xterm.". Could you indicate what it is the problem?
I use ubuntu-20.04.4-live-server-amd64.iso. Following is my procedure:
#cd /
#apt update && apt install make gcc-multilib build-essential automake -y && apt upgrade -y
#git clone --recursive https://github.com/rolandriegel/nload.git
#git clone --recursive https://github.com/mirror/ncurses.git
#cd /ncurses
#./configure
#make
#cd /nload
#./run_autotools
#CPPFLAGS=-I/ncurses/include LDFLAGS="-L/ncurses/lib -static" ./configure
#make
#cd /nload/src
#./nload
Error opening terminal: xterm.
@quaggalinux Thanks to developers of Alpine linux (based on MUSL
) and nload it is quite easy:
Run inside of Alpine:
apk update && apk add git bash autoconf automake linux-headers build-base ncurses-dev ncurses-static
git clone https://github.com/berghetti/nload.git nload && cd nload
./run_autotools # no need to edit because of "apk add bash"
LDFLAGS="-static" ./configure --prefix=/opt/nload
make -j9 && make install
# To check static linking. Output may be little bit different depending on platform and other things...
file /opt/nload/bin/nload
/opt/nload/bin/nload: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, with debug_info, not stripped
@flajr WOW! Today must a great day!
I successfully compiled a static nload executive file follow your hints.
Following is my procedure:
I installed ubuntu-20.04.5-live-server-amd64.iso
and then installed docker on ubuntu
#docker pull alpine:latest
#docker run -dit -p 2222:22 --name=ok -v /tmp:/tmp alpine
#docker ps -a
#docker attach e901a5205bc3 (e901a5205bc3 is alpine CONTAINER ID)
#cd /
#apk update && apk add git bash autoconf automake linux-headers build-base ncurses-dev ncurses-static
#git clone https://github.com/rolandriegel/nload
#cd /nload
#./run_autotools
#LDFLAGS="-static" ./configure --prefix=/opt/nload
#make -j9
#cd src
#cp nload /tmp/
#exit
Finally I can copy the static nload executive file form ubuntu host's tmp directory.
You are the Top Gun!
@flajr Would you please take a look at project:
https://github.com/gdm85/iftop
I also open an issues "gdm85/iftop#3" asking help for static compile.
Thank you!