Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to build a static nload binary ? #15

Open
quaggalinux opened this issue Jan 4, 2022 · 5 comments
Open

How to build a static nload binary ? #15

quaggalinux opened this issue Jan 4, 2022 · 5 comments

Comments

@quaggalinux
Copy link

Hi,

Could you tell me how to build a static nload binary ?
Or, is there any parameters to make static nload binary ?

Thank you!

@paunstefan
Copy link

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.

@quaggalinux
Copy link
Author

@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.

@flajr
Copy link

flajr commented Nov 11, 2022

@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

@quaggalinux
Copy link
Author

@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!

@quaggalinux
Copy link
Author

@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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants