OpenWrt Forum Archive

Topic: Link problem when building openwrt with external toolchain

The content of this topic has been archived on 30 Mar 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hi all,

I have built openwrt trunk sucessfully for my 3 TP-Link models for nearly 1 year.

It worked if I use internal toolchain, but after getting external toolchain from openwrt,
and change the config to use external toolchain to build, it stopped in netifd and ntpclient
and some other packages when linking the binaries, complaining missing libdl.so.0 and
libpthread.so.0
It can build completely, if I copy these files from toolchain to staging_dir and re-run make.

Any idea on the problem? Attached the log file when building...
External toolchain path:
/workspace/OpenWrt-Toolchain-ar71xx-for-mips_r2-gcc-4.6-linaro_uClibc-0.9.33.2/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2

Copy libdl.so.0 and libpthread.so.0 from toolchain to here then OK:
staging_dir/target-mips-openwrt-linux-uclibc/usr/lib/

[100%] Building C object CMakeFiles/netifd.dir/system-linux.c.o
Linking C executable netifd
/workspace/OpenWrt-Toolchain-ar71xx-for-mips_r2-gcc-4.6-linaro_uClibc-0.9.33.2/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/bin/../lib/gcc/mips-openwrt-linux-uclibc/4.6.3/../../../../mips-openwrt-linux-uclibc/bin/ld: warning: libdl.so.0, needed by /workspace/jenkins/openwrt-trunk/staging_dir/target-mips-openwrt-linux-uclibc/usr/lib/libuci.so, not found (try using -rpath or -rpath-link)
/workspace/jenkins/openwrt-trunk/staging_dir/target-mips-openwrt-linux-uclibc/usr/lib/libuci.so: undefined reference to `dlclose'
/workspace/jenkins/openwrt-trunk/staging_dir/target-mips-openwrt-linux-uclibc/usr/lib/libuci.so: undefined reference to `dlopen'
/workspace/jenkins/openwrt-trunk/staging_dir/target-mips-openwrt-linux-uclibc/usr/lib/libuci.so: undefined reference to `dlsym'
collect2: ld returned 1 exit status

make[6]: *** [netifd] Error 1
make[6]: Leaving directory `/workspace/jenkins/openwrt-trunk/build_dir/target-mips-openwrt-linux-uclibc/netifd-2012-09-29'
make[5]: *** [CMakeFiles/netifd.dir/all] Error 2
make[5]: Leaving directory `/workspace/jenkins/openwrt-trunk/build_dir/target-mips-openwrt-linux-uclibc/netifd-2012-09-29'
make[4]: *** [all] Error 2
make[4]: Leaving directory `/workspace/jenkins/openwrt-trunk/build_dir/target-mips-openwrt-linux-uclibc/netifd-2012-09-29'
make[3]: *** [/workspace/jenkins/openwrt-trunk/build_dir/target-mips-openwrt-linux-uclibc/netifd-2012-09-29/.built] Error 2

After copying

jenkins@fai-build:/workspace/jenkins/openwrt-trunk$ cp /workspace/OpenWrt-Toolchain-ar71xx-for-mips_r2-gcc-4.6-linaro_uClibc-0.9.33.2/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/mips-openwrt-linux-uclibc/lib/libdl.so.0 staging_dir/target-mips-openwrt-linux-uclibc/usr/lib/

jenkins@fai-build:/workspace/jenkins/openwrt-trunk$ cp /workspace/OpenWrt-Toolchain-ar71xx-for-mips_r2-gcc-4.6-linaro_uClibc-0.9.33.2/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/mips-openwrt-linux-uclibc/lib/libpthread.so.0 staging_dir/target-mips-openwrt-linux-uclibc/usr/lib/

jenkins@fai-build:/workspace/jenkins/openwrt-trunk$ make
make[1] world
make[2] target/compile
make[3] -C target/linux compile
make[2] package/compile
make[3] -C package/toolchain compile
make[3] -C package/libs/libnl-tiny compile
make[3] -C package/libs/libjson-c compile
make[3] -C package/libs/libubox compile
make[3] -C package/lua compile
make[3] -C package/ubus compile
make[3] -C package/uci compile
make[3] -C package/netifd compile
make[3] -C package/opkg host-compile

(Last edited by lazyfai on 10 Oct 2012, 03:40)

I discovered another simple way to fix it by looking at the link/compile commands...
in toolchain/bin/mips-openwrt-linux-uclibc-wrapper.sh,
TOOLCHAIN_SYSROOT="$TOOLCHAIN_BIN_DIR/../.."
This pointed to the parent of the actual toolchain directory, correcting it by changing to
TOOLCHAIN_SYSROOT="$TOOLCHAIN_BIN_DIR/.."
Then whole process works fine again.

The discussion might have continued from here.