Skip to content

don't get echoserver static #849

Closed
Closed

Description

@divinity76

i tried to get echoserver static, but it didn't work, any idea why?

I did basically exactly:

#!/bin/bash
set -euxo pipefail

git clone  --depth 1 'https://github.com/wolfSSL/wolfssh.git'

cd wolfssh

git clone 'https://github.com/wolfSSL/wolfssl.git' --depth 1

cd wolfssl

mkdir install

./autogen.sh

CFLAGS='-s -Os' CXXFLAGS='-s -Os' ./configure --enable-static --disable-shared --prefix="$(pwd)/install" --enable-psa-lib-static

CFLAGS='-s -Os' CXXFLAGS='-s -Os' make -j$(nproc)

make install

cd ..

wget -O- 'https://github.com/wolfSSL/wolfssh/pull/848.diff' | git apply -

mkdir install

./autogen.sh

CFLAGS='-s -Os' ./configure --enable-static --disable-shared --enable-scp --enable-sftp --enable-shell --enable-cryptonly --with-wolfssl=wolfssl/install/ --prefix="$(pwd)/install"

CFLAGS='-s -Os' make -j$(nproc)

make install

(ps had to apply PR #848 to get it to compile)

and then...

$ ldd examples/echoserver/echoserver
	linux-vdso.so.1 (0x00007ffff7fc3000)
	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007ffff7e1a000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007ffff7c00000)
	/lib64/ld-linux-x86-64.so.2 (0x00007ffff7fc5000)

it's not static. any suggestions?

Activity

  1. self-assigned this
    on Nov 13, 2025
  2. embhorn commented on Nov 13, 2025

    @embhorn
    Member

    Hello @divinity76

    Thanks for contacting wolfSSL Support. Could you tell us a bit about your project?

    The example does use external libs. The math lib dependency can be removed by configuring wolfSSL:

    #if 1
        /* Use table for DH instead of -lm (math) lib dependency */
        #if 1
            #define WOLFSSL_DH_CONST
            #define HAVE_FFDHE_2048
            //#define HAVE_FFDHE_4096
            //#define HAVE_FFDHE_6144
            //#define HAVE_FFDHE_8192
        #endif
    #else
        #define NO_DH
    #endif
    

    The C lib and other dependencies will require you to build those libs as static and modify the make file to use those static libs. This would be more common in an embedded library context. You are building the defaults in linux, so the shared libs are being pulled in.

    Let us know if you have further questions.

    Thanks,
    @embhorn

  3. divinity76 commented on Nov 18, 2025

    @divinity76
    ContributorAuthor

    got it static by bypassing the makefile with

    $ gcc -static -s -Os -DHAVE_CONFIG_H -I. -Iinstall/include -Iwolfssl/install/include examples/echoserver/echoserver.c install/lib/libwolfssh.a wolfssl/install/lib/libwolfssl.a -lm -o examples/echoserver/echoserver-static

    $ file examples/echoserver/echoserver-static
    examples/echoserver/echoserver-static: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, BuildID[sha1]=190d5cf4b1a16a8b3463e0f7248fe0e49ba36a5f, for GNU/Linux 3.2.0, stripped

    ✅

  4. divinity76 commented on Nov 22, 2025

    @divinity76
    ContributorAuthor

    Found a better way that does not bypass makefile:

    $make LDFLAGS="-static -all-static -Lwolfssl/install/lib" examples/echoserver/echoserver
      CC       examples/echoserver/echoserver.o
      CC       src/libwolfssh_la-ssh.lo
      CC       src/libwolfssh_la-internal.lo
      CC       src/libwolfssh_la-log.lo
      CC       src/libwolfssh_la-io.lo
      CC       src/libwolfssh_la-port.lo
      CC       src/libwolfssh_la-wolfscp.lo
      CC       src/libwolfssh_la-wolfsftp.lo
      CC       src/libwolfssh_la-wolfterm.lo
      CCLD     src/libwolfssh.la
      CCLD     examples/echoserver/echoserver
    /usr/bin/ld: examples/echoserver/echoserver.o: in function `echoserver_test':
    echoserver.c:(.text+0x2910): warning: Using 'getpwnam' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
    $ ldd examples/echoserver/echoserver
    	not a dynamic executable
    
    • However, glibc have an issue with using getpwnam statically, which can be solved by using musl instead of glibc, e.g
    $ CC=musl-gcc ./configure --enable-static --disable-shared --enable-scp --enable-sftp --enable-shell --with-wolfssl=wolfssl/install-musl
    (...)
    $ make LDFLAGS="-static -all-static -Lwolfssl/install/lib" examples/echoserver/echoserver
    

    However echoserver does not compile cleanly on musl, you have to replace #include <sys/errno.h> with #include <errno.h> to compile on musl. And that is actually an issue in the wolfssh code: historically many systems used sys/errno.h , but the C standard always, since C89, said it was errno.h, so unless you need to support pre-C89 compilers, yeah.. imma open a PR for that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions