Forum

Unable to compile with mbedtls 2.0.0.

Sjir Bagmeijer
6 August 2015, 11:20
Hello,

I am trying to upgrade the rpms for Hiawatha in my repository tot he new version 9.14 but I am probably doing something wrong and it seems not to compile correctly with all my attempts.

I build my mbedtls with this:
First enable "MBEDTLS_THREADING_PTHREAD" and "MBEDTLS_THREADING_C" by doing this:
sed -i 's|//\(#define MBEDTLS_THREADING_C\)|\1|' include/mbedtls/config.h
sed -i 's|//\(#define MBEDTLS_THREADING_PTHREAD\)|\1|' include/mbedtls/config.h

(also tried it manually just to make sure my sed was not wrong)

And with the following cmake flags:
cmake -DCMAKE_BUILD_TYPE:String="Release" -DUSE_SHARED_MBEDTLS_LIBRARY:BOOL=TRUE -DENABLE_ZLIB_SUPPORT:BOOL=TRUE -DUSE_PKCS11_HELPER_LIBRARY:BOOL=TRUE .


No problems here mbedtls compiles fine, now I try to compile Hiawatha by using the shared mbedtls library that I compile with the below cmake.
cmake -DCMAKE_INSTALL_PREFIX="" \
-DCMAKE_INSTALL_BINDIR=%{_bindir} \
-DCMAKE_INSTALL_SBINDIR=%{_sbindir} \
-DCMAKE_INSTALL_SYSCONFDIR=%{_sysconfdir} \
-DCMAKE_INSTALL_LIBDIR=%{_libdir} \
-DCMAKE_INSTALL_MANDIR=%{_mandir} \
-DCONFIG_DIR=%{_sysconfdir}/hiawatha \
-DLOG_DIR=%{_localstatedir}/log/hiawatha \
-DPID_DIR=%{_localstatedir}/run \
-DWORK_DIR=%{_localstatedir}/cache/hiawatha \
-DWEBROOT_DIR=/srv/hiawatha/public \
-DENABLE_CACHE=on \
-DENABLE_DEBUG=off \
-DENABLE_IPV6=on \
-DENABLE_MONITOR=on \
-DENABLE_RPROXY=on \
-DENABLE_SSL=on \
-DENABLE_TOMAHAWK=on \
-DENABLE_TOOLKIT=on \
-DENABLE_XSLT=on \
-DUSE_SYSTEM_MBEDTLS=on


But it already complains it cannot find my shared mbedtls library:
-- Looking for SO_ACCEPTFILTER - not found
CMake Warning at CMakeLists.txt:106 (message):
Make sure the mbed TLS shared library has been built with the
MBEDTLS_THREADING_PTHREAD and MBEDTLS_THREADING_C flags set. Otherwise, it
may crash the Hiawatha webserver.


-- Configuring done
-- Generating done
CMake Warning:
Manually-specified variables were not used by the project:

ENABLE_DEBUG
ENABLE_SSL


And then finally Hiawatha crashes little further down the line:
[ 68%] Building C object CMakeFiles/hiawatha.dir/src/xslt.c.o
Linking C executable hiawatha
/usr/bin/ld: CMakeFiles/hiawatha.dir/src/tls.c.o: undefined reference to symbol 'mbedtls_x509_crt_parse_file'
/usr/local/lib/libmbedx509.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
CMakeFiles/hiawatha.dir/build.make:787: recipe for target 'hiawatha' failed
make[2]: *** [hiawatha] Error 1
CMakeFiles/Makefile2:95: recipe for target 'CMakeFiles/hiawatha.dir/all' failed
make[1]: *** [CMakeFiles/hiawatha.dir/all] Error 2
Makefile:136: recipe for target 'all' failed
make: *** [all] Error 2


Do you see anything perhaps I do wrong? All this worked fine on Hiawatha 9.13 with mbedtls 1.3.11.
Sjir Bagmeijer
6 August 2015, 13:46
I understand now that the "CMake Warning" is just a informational message and I can ignore it if I built the shared library correctly.

Still stuck with the other error:
/usr/local/lib/libmbedx509.so.0: error adding symbols: DSO missing from command line

No idea how to get it resolved, if I google it means something linking wise is going wrong?
Sjir Bagmeijer
9 August 2015, 20:29
It is very strange it works fine if I compile it with the build in mbedtls as soon as I try to use a own compiled mbedtls it keeps breaking.

Was anything changed in the way to use your own mbedtls?
Hugo Leisink
12 August 2015, 08:25
Don't use ENABLE_DEBUG, unless you plan to change Hiawatha's code. ENABLE_SSL has been replaced with ENABLE_TLS.
Sjir Bagmeijer
12 August 2015, 18:38
Hi Hugo! Thank you very much for the response!

I changed the settings as you said but it still keeps breaking on the same error:

/usr/bin/ld: CMakeFiles/wigwam.dir/src/wigwam.c.o: undefined reference to symbol 'mbedtls_x509_crt_parse_file'
/usr/lib64/libmbedx509.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
CMakeFiles/wigwam.dir/build.make:285: recipe for target 'wigwam' failed
make[2]: *** [wigwam] Error 1
CMakeFiles/Makefile2:165: recipe for target 'CMakeFiles/wigwam.dir/all' failed
make[1]: *** [CMakeFiles/wigwam.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....

/usr/bin/ld: CMakeFiles/hiawatha.dir/src/tls.c.o: undefined reference to symbol 'mbedtls_x509_crt_parse_file'
/usr/lib64/libmbedx509.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
CMakeFiles/hiawatha.dir/build.make:787: recipe for target 'hiawatha' failed
make[2]: *** [hiawatha] Error 1
CMakeFiles/Makefile2:95: recipe for target 'CMakeFiles/hiawatha.dir/all' failed
make[1]: *** [CMakeFiles/hiawatha.dir/all] Error 2


I now used the following cmake:
cmake -DCMAKE_INSTALL_PREFIX="" \
-DCMAKE_INSTALL_BINDIR=%{_bindir} \
-DCMAKE_INSTALL_SBINDIR=%{_sbindir} \
-DCMAKE_INSTALL_SYSCONFDIR=%{_sysconfdir} \
-DCMAKE_INSTALL_LIBDIR=%{_libdir} \
-DCMAKE_INSTALL_MANDIR=%{_mandir} \
-DCONFIG_DIR=%{_sysconfdir}/hiawatha \
-DLOG_DIR=%{_localstatedir}/log/hiawatha \
-DPID_DIR=%{_localstatedir}/run \
-DWORK_DIR=%{_localstatedir}/cache/hiawatha \
-DWEBROOT_DIR=/srv/hiawatha/public \
-DENABLE_CACHE=on \
-DENABLE_IPV6=on \
-DENABLE_MONITOR=on \
-DENABLE_RPROXY=on \
-DENABLE_TLS=on \
-DENABLE_TOMAHAWK=on \
-DENABLE_TOOLKIT=on \
-DENABLE_XSLT=on \
-DUSE_SYSTEM_MBEDTLS=on


I am not sure where it goes wrong, to be sure I also double checked if nothing was wrong with the own compiled mbedtls but that seems to work fine in other projects I link it with.
Hugo Leisink
13 August 2015, 12:09
It seems something goes wrong during the installation of mbed TLS. https://github.com/ARMmbed/mbedtls/issues/237. Let's see what the mbed TLS developers have to say.
Sjir Bagmeijer
13 August 2015, 12:49
Aah I see thank you so much Hugo! I will try to build it later tonight with the patch they have in their development branch to see if things work then!
Sjir Bagmeijer
14 August 2015, 10:21
Somehow even with the development branch it does not work:

if I search for the files:
[root@f22-32bit ~]# locate libmbedx509
/usr/lib/libmbedx509.a
/usr/lib/libmbedx509.so
/usr/lib/libmbedx509.so.0
/usr/lib/libmbedx509.so.2.0.0
[root@f22-32bit ~]# locate libmbedcrypto.a
/usr/lib/libmbedcrypto.a
[root@f22-32bit ~]# locate libmbedtls
/usr/lib/libmbedtls.a
/usr/lib/libmbedtls.so
/usr/lib/libmbedtls.so.10
/usr/lib/libmbedtls.so.2.0.0


I still get this error:
[ 72%] Building C object CMakeFiles/hiawatha.dir/src/log.c.o
Linking C executable wigwam
/usr/bin/ld: CMakeFiles/wigwam.dir/src/wigwam.c.o: undefined reference to symbol 'mbedtls_x509_crt_parse_file'
/lib/libmbedx509.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
CMakeFiles/wigwam.dir/build.make:285: recipe for target 'wigwam' failed
make[2]: *** [wigwam] Error 1
CMakeFiles/Makefile2:165: recipe for target 'CMakeFiles/wigwam.dir/all' failed
make[1]: *** [CMakeFiles/wigwam.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 74%] Building C object CMakeFiles/hiawatha.dir/src/memdbg.c.o
[ 76%] [ 78%] Building C object CMakeFiles/hiawatha.dir/src/mimetype.c.o
Building C object CMakeFiles/hiawatha.dir/src/monitor.c.o
[ 80%] Building C object CMakeFiles/hiawatha.dir/src/rproxy.c.o
[ 82%] Building C object CMakeFiles/hiawatha.dir/src/send.c.o
[ 84%] Building C object CMakeFiles/hiawatha.dir/src/serverconfig.c.o
[ 86%] Building C object CMakeFiles/hiawatha.dir/src/session.c.o
[ 88%] Building C object CMakeFiles/hiawatha.dir/src/tls.c.o
[ 90%] Building C object CMakeFiles/hiawatha.dir/src/target.c.o
[ 92%] Building C object CMakeFiles/hiawatha.dir/src/tomahawk.c.o
[ 94%] Building C object CMakeFiles/hiawatha.dir/src/toolkit.c.o
[ 96%] [ 98%] Building C object CMakeFiles/hiawatha.dir/src/userconfig.c.o
Building C object CMakeFiles/hiawatha.dir/src/workers.c.o
[100%] Building C object CMakeFiles/hiawatha.dir/src/xslt.c.o
Linking C executable hiawatha
/usr/bin/ld: CMakeFiles/hiawatha.dir/src/tls.c.o: undefined reference to symbol 'mbedtls_x509_crt_parse_file'
/lib/libmbedx509.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
CMakeFiles/hiawatha.dir/build.make:787: recipe for target 'hiawatha' failed
make[2]: *** [hiawatha] Error 1
CMakeFiles/Makefile2:95: recipe for target 'CMakeFiles/hiawatha.dir/all' failed
make[1]: *** [CMakeFiles/hiawatha.dir/all] Error 2
Makefile:136: recipe for target 'all' failed
make: *** [all] Error 2
error: Bad exit status from /var/tmp/rpm-tmp.mkOAFJ (%build)


Are the files supposed to be in another directory?
Hugo Leisink
14 August 2015, 11:38
What I did for mbed TLS was a simple 'make && make install'. This installed the library in /usr/local/lib. I manually copied libmbedcrypto.a and libmbedx509.a to it. Make sure you use this CMakeLists.txt file for Hiawatha. It has some fixes as lines 116, 146 and 147.
Sjir Bagmeijer
14 August 2015, 11:52
Building with this new CMakeLists.txt makes it work! Thank you so much Hugo!
Hugo Leisink
14 August 2015, 12:16
You're welcome!
This topic has been closed.