CESNET / netopeer2

NETCONF toolset
BSD 3-Clause "New" or "Revised" License
291 stars 186 forks source link

Cross compile linker errors #1464

Open pepa-cz opened 10 months ago

pepa-cz commented 10 months ago

When cross compiling for mips architecture I get the following errors (output is stripped here but all of them are similar to this):

[100%] Linking C executable ../netopeer2-cli
/usr/src/racom/ra2_fwbuild/SDK/src/ra2_sdk/OCTEON-SDK/OSELAS.Toolchain-2022.10.0/mips64-linux-gnuabi64/gcc-12.3.0-glibc-2.36-binutils-2.40-kernel-6.1.14-sanitized/bin/../lib/gcc/mips64-linux-gnuabi64/12.3.0/../../../../mips64-linux-gnuabi64/bin/ld: warning: libssl.so.3, needed by /usr/src/racom/ra2_fwbuild/staging/lib/libnetconf2.so, not found (try using -rpath or -rpath-link)
/usr/src/racom/ra2_fwbuild/SDK/src/ra2_sdk/OCTEON-SDK/OSELAS.Toolchain-2022.10.0/mips64-linux-gnuabi64/gcc-12.3.0-glibc-2.36-binutils-2.40-kernel-6.1.14-sanitized/bin/../lib/gcc/mips64-linux-gnuabi64/12.3.0/../../../../mips64-linux-gnuabi64/bin/ld: warning: libcrypto.so.3, needed by /usr/src/racom/ra2_fwbuild/staging/lib/libnetconf2.so, not found (try using -rpath or -rpath-link)
/usr/src/racom/ra2_fwbuild/SDK/src/ra2_sdk/OCTEON-SDK/OSELAS.Toolchain-2022.10.0/mips64-linux-gnuabi64/gcc-12.3.0-glibc-2.36-binutils-2.40-kernel-6.1.14-sanitized/bin/../lib/gcc/mips64-linux-gnuabi64/12.3.0/../../../../mips64-linux-gnuabi64/bin/ld: /usr/src/racom/ra2_fwbuild/staging/lib/libssh.so: undefined reference to `BN_copy@OPENSSL_3.0.0'
....
....
collect2: error: ld returned 1 exit status
cli/CMakeFiles/netopeer2-cli.dir/build.make:227: recipe for target 'netopeer2-cli' failed
make[2]: *** [netopeer2-cli] Error 1
CMakeFiles/Makefile2:223: recipe for target 'cli/CMakeFiles/netopeer2-cli.dir/all' failed
make[1]: *** [cli/CMakeFiles/netopeer2-cli.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2

Linker probably cannot find openssl and crypto libraries. CMake configuration:

    cmake \
        -DCMAKE_INSTALL_PREFIX= \
        -DCMAKE_INCLUDE_PATH=$PREFIX/include \
        -DCMAKE_LIBRARY_PATH=$PREFIX/lib \
        -DCMAKE_BUILD_TYPE:String="Release" \
        -DSYSREPOCTL_EXECUTABLE=$PREFIX/bin/sysrepoctl \
        -DSYSREPOCFG_EXECUTABLE=$PREFIX/bin/sysrepocfg \
        -DCMAKE_STRIP=$STRIP \
        -DINSTALL_MODULES=OFF \
        -DGENERATE_HOSTKEY=OFF \
        -DMERGE_LISTEN_CONFIG=OFF \
        $EXTSRCDIR

CMakeFiles/netopeer2-cli.dir/link.txt:

/usr/src/racom/ra2_fwbuild/OCTEON-SDK/tools/bin/mips64-linux-gnuabi64-gcc  -march=octeon3 -mabi=64 -mno-branch-likely -mabicalls -O3 -Wall -Wextra -std=c99  -L/usr/src/racom/ra2_fwbuild/staging/lib -march=octeon3 -mabi=64 CMakeFiles/netopeer2-server.dir/src/main.c.o CMakeFiles/netopeer2-server.dir/compat/compat.c.o CMakeFiles/serverobj.dir/src/common.c.o CMakeFiles/serverobj.dir/src/netconf.c.o CMakeFiles/serverobj.dir/src/netconf_monitoring.c.o CMakeFiles/serverobj.dir/src/netconf_nmda.c.o CMakeFiles/serverobj.dir/src/netconf_subscribed_notifications.c.o CMakeFiles/serverobj.dir/src/netconf_confirmed_commit.c.o CMakeFiles/serverobj.dir/src/subscribed_notifications.c.o CMakeFiles/serverobj.dir/src/yang_push.c.o CMakeFiles/serverobj.dir/src/log.c.o CMakeFiles/serverobj.dir/src/err_netconf.c.o CMakeFiles/serverobj.dir/src/netconf_server.c.o CMakeFiles/serverobj.dir/src/netconf_server_ssh.c.o  -o netopeer2-server -rdynamic -lnetconf2 -lssh -lyang -lsysrepo

However, if I add -DCMAKE_EXE_LINKER_FLAGS=-Wl,-L$PREFIX/lib,-lssl,-lcrypto crosscompiling is successful.

$ netopeer2-server -V
netopeer2-server 2.1.62
michalvasko commented 10 months ago

I am not sure that this is a problem in netopeer2, it is not using libssl directly so no reason for it to link it. That is, netopeer2-server, netopeer2-cli should be linking libssl and is, I have just checked.

pepa-cz commented 10 months ago

I am not sure that this is a problem in netopeer2, it is not using libssl directly so no reason for it to link it.

Okay, I will check our cross-compile environment and let you know if something is wrong there.

jktjkt commented 10 months ago

The error message says that the version of OpenSSL that your libnetconf2 is linked against is something different than the version of OpenSSL that's available at /usr/src/racom/ra2_fwbuild/staging/lib/libssh.so (that's the message undefined reference to BN_copy@OPENSSL_3.0.0). The previous two error messages are a result of that AFAIK. Maybe your OpenSSL version has changed, and you are trying to reuse build artifacts or some partial results of the build? Starting from scratch should fix that.

I don't know which tools you're using for cross-builds, but I can really recommend something like Buildroot (which we use and are familiar with internally). I've also heard that Yocto works fine. I do not recommend homemade recipes.