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 statically compile iperf3? #544

Closed
JodieChuang opened this issue Apr 4, 2017 · 12 comments
Closed

How to statically compile iperf3? #544

JodieChuang opened this issue Apr 4, 2017 · 12 comments
Labels

Comments

@JodieChuang
Copy link

JodieChuang commented Apr 4, 2017

Dear iperf3 developers,

I want to use iperf3 in a minimal filesystem with a linux kernel. i have to statically compile the programs to use inside the filesystem. Is that possible to statically compile iperf3?
I did
$ ./configure --build=arm-none-linux-gnueabi --host=arm-none-linux-gnueabi CFLAGS=-static CXXFLAGS=-static
$ make

But I get
/src$ file iperf3
iperf3: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=33df741e068aaf7a9ae8a24a6243de87c35c6ca5, not stripped

best regards,
Jiahuan

@TheRealDJ
Copy link
Contributor

./configure --enable-static --disable-shared ; make ; make install

@bmah888
Copy link
Contributor

bmah888 commented Apr 6, 2017

I haven't tried this for a long time, but that looks the right answer, thanks @TheRealDJ!

@bmah888 bmah888 closed this as completed Apr 6, 2017
@oliwer
Copy link

oliwer commented Nov 14, 2019

This does not seem to work anymore. It builds the static library but not the executables.

@shibumi
Copy link

shibumi commented May 4, 2020

Hi,
I can confirm this. I tried building iperf3 as static executable but it still links against a few libraries:

❯ ldd ./iperf3
	linux-vdso.so.1 (0x00006284def24000)
	libcrypto.so.1.1 => /usr/lib/libcrypto.so.1.1 (0x00006284debef000)
	libc.so.6 => /usr/lib/libc.so.6 (0x00006284dea29000)
	libdl.so.2 => /usr/lib/libdl.so.2 (0x00006284dea24000)
	libpthread.so.0 => /usr/lib/libpthread.so.0 (0x00006284dea02000)
	/lib64/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2 (0x00006284def26000)

build via: ./configure --enable-static --disable-shared

@mariusleu
Copy link

This worked for me:

./configure "LDFLAGS=--static" --disable-shared --without-sctp
make
make install
$ ldd iperf3 
	not a dynamic executable

It's also on the documentation: https://software.es.net/iperf/faq.html

@adroutley
Copy link

hi there,

i used these configure options to create a static iperf3, but my ./configure gives me this:-

./configure "LDFLAGS=--static" --disable-shared --without-sctp
configure: loading site script /usr/share/site/x86_64-unknown-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether make supports nested variables... (cached) yes
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking how to print strings... printf
checking whether make supports the include directive... yes (GNU style)
checking for gcc... gcc
checking whether the C compiler works... no
configure: error: in /home/andrew/Downloads/iperf3': configure: error: C compiler cannot create executables See config.log' for more details

a simple
./configure --disable-shared --without-sctp
...always works

nothing in config.log stands out

any ideas why i get "C compiler cannot create executables" ??? i have googled the heck out of it and also read https://software.es.net/iperf/faq.html multiple times....

my environment:-

uname -a
Linux lap 5.11.15-1-default #1 SMP Fri Apr 16 16:47:34 UTC 2021 (64fb5bf) x86_64 x86_64 x86_64 GNU/Linux
cat /etc/issue
Welcome to openSUSE Tumbleweed 20210422 - Kernel \r (\l).

(all "base development" packages have been installed via [YAST)]

@TheRealDJ
Copy link
Contributor

Short Answer

You are missing the libc static development files.
"..." indicates output not posted

# cat /etc/os-release | grep '^NAME=\|^VERSION_ID='
NAME="openSUSE Tumbleweed"
VERSION_ID="20210428"

# zypper install glibc-devel-static
...

# ./configure --enable-static --enable-static-bin --disable-shared
...

# make -j4
...

# file src/iperf3
src/iperf3: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, BuildID[sha1]=18fa0d433830d9b68f193ebce3ec5a54bb09afc6, for GNU/Linux 3.2.0, with debug_info, not stripped

# ldd src/iperf3
	not a dynamic executable

Long Answer

I found the error by trying to compile a simple printf("Hello\n"); program

Before glibc-devel-static install

# gcc -static -o hello hello.c 
/usr/lib64/gcc/x86_64-suse-linux/10/../../../../x86_64-suse-linux/bin/ld: cannot find -lc
collect2: error: ld returned 1 exit status

Error = cannot find -lc
-lc = statically link to libc

After glibc-devel-static install

# gcc -static -o hello hello.c 

# file hello
hello: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, BuildID[sha1]=9e925bb7a1c61f5f782d13c64b96252f2cfe7811, for GNU/Linux 3.2.0, with debug_info, not stripped

# ldd hello
	not a dynamic executable

Without -static flag

# gcc -o hello hello.c 

# file hello
hello: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=632761a8aedf8127d7a53414ad9cef1b1ffeb4d2, for GNU/Linux 3.2.0, with debug_info, not stripped

# ldd hello
	linux-vdso.so.1 (0x00007ffefd9a4000)
	libc.so.6 => /lib64/libc.so.6 (0x00007febad7d4000)
	/lib64/ld-linux-x86-64.so.2 (0x00007febad9ab000)

DJ

@adroutley
Copy link

Dear TheRealDJ, it works- you're a greek god mate! (I have just sacrificed a bull in your honor.....) Although in my defence I actually did have this library already installed just the "-32-bit" flavour which was not being used. ;)

@adroutley
Copy link

Hi again @TheRealDJ

Thanks for helping me do the static build of iperf.

just a small iteration to this usecase: is it possible to compile iperf with dynamic libraries, but force make to copy each required library into a side location ("./configure --prefix=/tmp/portable" ), where iperf can use the side-library on the foreign server ?

BACKGROUND:
Static linking is the best way to make a utility truly "portable", but what if the resultant binary is huge?  Can we force-create a portable /lib that we can also move to the foreign server ?

@TheRealDJ
Copy link
Contributor

You could, but I don't know why you would want to.

# mkdir -p /usr/local/iperf3
# ./configure --disable-static --prefix=/usr/local/iperf3
# make -j4
# make install

# du -sh /usr/local/iperf3/
752K	/usr/local/iperf3/

# ls -aFlh iperf3-static*
-rwxr-xr-x 1 root root 1.8M May 21 16:26 iperf3-static*
-rwxr-xr-x 1 root root 1.2M May 21 16:17 iperf3-static-stripped*

So the unstripped static binary is 1.8M, stripped 1.2M ... The dynamic method results in 752K. You would save ~460K using dynamic.

On the remote server, you would have to create the prefix path, copy the files in, and create /etc/ld.so.conf.d/iperf3.conf with the following:

# iperf3 dynamic libs
/usr/local/iperf3/lib

Then run ldconfig to update cache.

My opinion: Seems like quite a bit of effort to save 460K.

@adroutley
Copy link

Actually I meant it not just for iperf specifically, but rather any application where the resultant static binary would be too large.

Ok so the secret sauce is:-

./configure --disable-static --prefix=/usr/local/iperf3

....But unfortunately the target server is Holy and cannot be modified, so changing /etc/ld.so.conf.d cannot be done but I believe I can point to my portable libraries this way instead:-

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/iperf3/lib

....and run it standalone:-

/usr/local/iperf3/bin/iperf

Thx!

@smashingly
Copy link

smashingly commented Mar 8, 2024

Just replying to confirming that this worked for me - statically compiling it on an AWS VM running Amazon Linux and SCP'ing it to an Azure VM running RHEL 8. The AWS VM had s/w repo access and already had iperf 3.16, but I needed 3.16 on the Azure VM which had no internet access and no s/w repo access. So I was able to DNF install gcc/make, the glibc dev static module (which was named slightly differently under Amazon Linux - but it was easy to find by grepping the output of 'DNF list' for 'glibc' and 'static'.
Your post (and this entire topic thread) really saved my bacon, thanks everyone, I was dealing with an iPerf3 hung test issue and getting both ends to the latest iPerf3 version helped me eliminate iPerf3 entirely as a cause.

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

No branches or pull requests

8 participants