[Libwebsockets] Compiling examples with static WolfSSL and static Libwebsockets

Joman Chu jomanchu at gmail.com
Wed May 19 04:59:19 CEST 2021


Hi all,

I'm trying to compile the examples but statically linking against
WolfSSL and Libwebsockets, but the compilation fails when linking with
one of the examples, missing references to `pow` and `log` in wolfssl.
I can successfully get it to link if I add a `-lm` at the end of the
invocation of gcc.

I'm compiling in an Ubuntu 20.04 container

Compiling WolfSSL:

```
./configure --enable-opensslextra --enable-debug --enable-static
--disable-shared --enable-intelasm --enable-aesni --disable-examples
--disable-crypttests --enable-libwebsockets
make CFLAGS=-DHAVE_EX_DATA
```

Compiling libwebsockets:

```
CFLAGS=-DHAVE_EX_DATA cmake .. -DLWS_WITH_SHARED:BOOL=OFF
-DCMAKE_BUILD_TYPE=DEBUG -DLWS_WITH_WOLFSSL=1
-DLWS_WOLFSSL_INCLUDE_DIRS=../../wolfssl
-DLWS_WOLFSSL_LIBRARIES=../../wolfssl/src/.libs/libwolfssl.a
-DLWS_WITH_MINIMAL_EXAMPLES=1
make
```

Error during `make` with api-test-lejp example:

```
make -f minimal-examples/api-tests/api-test-lejp/CMakeFiles/lws-api-test-lejp.dir/build.make
minimal-examples/api-tests/api-test-lejp/CMakeFiles/lws-api-test-lejp.dir/depend
make[2]: Entering directory '/workspace/libwebsockets/build'
cd /workspace/libwebsockets/build && /usr/bin/cmake -E cmake_depends
"Unix Makefiles" /workspace/libwebsockets
/workspace/libwebsockets/minimal-examples/api-tests/api-test-lejp
/workspace/libwebsockets/build
/workspace/libwebsockets/build/minimal-examples/api-tests/api-test-lejp
/workspace/libwebsockets/build/minimal-examples/api-tests/api-test-lejp/CMakeFiles/lws-api-test-lejp.dir/DependInfo.cmake
--color=
Dependee "/workspace/libwebsockets/build/minimal-examples/api-tests/api-test-lejp/CMakeFiles/lws-api-test-lejp.dir/DependInfo.cmake"
is newer than depender
"/workspace/libwebsockets/build/minimal-examples/api-tests/api-test-lejp/CMakeFiles/lws-api-test-lejp.dir/depend.internal".
Dependee "/workspace/libwebsockets/build/minimal-examples/api-tests/api-test-lejp/CMakeFiles/CMakeDirectoryInformation.cmake"
is newer than depender
"/workspace/libwebsockets/build/minimal-examples/api-tests/api-test-lejp/CMakeFiles/lws-api-test-lejp.dir/depend.internal".
Scanning dependencies of target lws-api-test-lejp
make[2]: Leaving directory '/workspace/libwebsockets/build'
make -f minimal-examples/api-tests/api-test-lejp/CMakeFiles/lws-api-test-lejp.dir/build.make
minimal-examples/api-tests/api-test-lejp/CMakeFiles/lws-api-test-lejp.dir/build
make[2]: Entering directory '/workspace/libwebsockets/build'
[ 39%] Building C object
minimal-examples/api-tests/api-test-lejp/CMakeFiles/lws-api-test-lejp.dir/main.c.o
cd /workspace/libwebsockets/build/minimal-examples/api-tests/api-test-lejp
&& /usr/bin/cc  -I/workspace/libwebsockets/include
-I/workspace/libwebsockets/build -I/workspace/libwebsockets/lib
-I/workspace/libwebsockets/lib/.
-I/workspace/libwebsockets/lib/plat/unix/.
-I/workspace/libwebsockets/lib/tls/. -I/workspace/wolfssl
-I/workspace/wolfssl/wolfssl -I/workspace/libwebsockets/lib/core/.
-I/workspace/libwebsockets/lib/misc/.
-I/workspace/libwebsockets/lib/system/./async-dns
-I/workspace/libwebsockets/lib/system/smd/.
-I/workspace/libwebsockets/lib/system/metrics/.
-I/workspace/libwebsockets/lib/core-net/.
-I/workspace/libwebsockets/lib/roles/.
-I/workspace/libwebsockets/lib/roles/http/.
-I/workspace/libwebsockets/lib/roles/http/./compression
-I/workspace/libwebsockets/lib/roles/h1/.
-I/workspace/libwebsockets/lib/roles/h2/.
-I/workspace/libwebsockets/lib/roles/ws/.
-I/workspace/libwebsockets/lib/roles/raw-skt/.
-I/workspace/libwebsockets/lib/roles/raw-file/.
-I/workspace/libwebsockets/lib/roles/listen/.
-I/workspace/libwebsockets/lib/event-libs/.
-I/workspace/libwebsockets/lib/event-libs/poll/../poll
-I/workspace/libwebsockets/lib/../include
-I/workspace/libwebsockets/build/lib/../include  -Wall -Wconversion
-Wsign-compare -Wstrict-aliasing -fvisibility=hidden -Wundef
-Wuninitialized -Wtype-limits -Wignored-qualifiers -DHAVE_EX_DATA
-Werror -pthread -g   -o CMakeFiles/lws-api-test-lejp.dir/main.c.o
-c /workspace/libwebsockets/minimal-examples/api-tests/api-test-lejp/main.c
[ 40%] Linking C executable ../../../bin/lws-api-test-lejp
cd /workspace/libwebsockets/build/minimal-examples/api-tests/api-test-lejp
&& /usr/bin/cmake -E cmake_link_script
CMakeFiles/lws-api-test-lejp.dir/link.txt --verbose=1
/usr/bin/cc -Wall -Wconversion -Wsign-compare -Wstrict-aliasing
-fvisibility=hidden -Wundef  -Wuninitialized -Wtype-limits
-Wignored-qualifiers -DHAVE_EX_DATA  -Werror -pthread -g  -rdynamic
CMakeFiles/lws-api-test-lejp.dir/main.c.o  -o
../../../bin/lws-api-test-lejp  -lpthread -lm -ldl
../../../lib/libwebsockets.a -lpthread -lm -ldl
/workspace/wolfssl/src/.libs/libwolfssl.a -lpthread
/usr/bin/ld: /workspace/wolfssl/src/.libs/libwolfssl.a(src_libwolfssl_la-dh.o):
in function `DiscreteLogWorkFactor':
/workspace/wolfssl/wolfcrypt/src/dh.c:985: undefined reference to `pow'
/usr/bin/ld: /workspace/wolfssl/wolfcrypt/src/dh.c:986: undefined
reference to `log'
/usr/bin/ld: /workspace/wolfssl/wolfcrypt/src/dh.c:986: undefined
reference to `pow'
collect2: error: ld returned 1 exit status
make[2]: *** [minimal-examples/api-tests/api-test-lejp/CMakeFiles/lws-api-test-lejp.dir/build.make:86:
bin/lws-api-test-lejp] Error 1
make[2]: Leaving directory '/workspace/libwebsockets/build'
make[1]: *** [CMakeFiles/Makefile2:3768:
minimal-examples/api-tests/api-test-lejp/CMakeFiles/lws-api-test-lejp.dir/all]
Error 2
make[1]: Leaving directory '/workspace/libwebsockets/build'
make: *** [Makefile:163: all] Error 2
```

I got it to link successfully by adding a -lm at the end of the
invocation of gcc:

```
cd /workspace/libwebsockets/build/minimal-examples/api-tests/api-test-lejp
/usr/bin/cc -Wall -Wconversion -Wsign-compare -Wstrict-aliasing
-fvisibility=hidden -Wundef  -Wuninitialized -Wtype-limits
-Wignored-qualifiers -DHAVE_EX_DATA  -Werror -pthread -g  -rdynamic
CMakeFiles/lws-api-test-lejp.dir/main.c.o  -o
../../../bin/lws-api-test-lejp  -lpthread -lm -ldl
../../../lib/libwebsockets.a -lpthread -lm -ldl
/workspace/wolfssl/src/.libs/libwolfssl.a -lpthread -lm
```

I'm not familiar enough with GCC/linker arguments to know what's going
on here, or how to resolve this via Cmake.  I would love any help
anyone can provide

Thanks!
Joman


More information about the Libwebsockets mailing list