I am trying to cross compile a program that I've written for OpenWRT. It's simple enough that I've never bothered with a Makefile
, let alone any of the GNU autotools. The "regular" build process, which includes building and linking to one non-standard library, is documented here.
I've run through the process of building an OpenWRT image, including libnml
, and I've also managed to build my library, so I've got the following files:
- Compiler —
${BUILDROOT}/staging_dir/toolchain-mips_24kc_gcc-8.4.0_musl/bin/mips-openwrt-linux-musl-gcc
- My non-standard library —
${BUILDROOT}/libsavl/libsavl.so.0.7.1
- JSON-C —
${BUILDROOT}/staging_dir/target-mips_24kc_musl/usr/lib/libjson-c.so.5.1.0
-
libmnl
—${BUILDROOT}staging_dir/target-mips_24kc_musl/usr/lib/libmnl.so.0.2.0
I'm now at the stage of trying to link my executable, and I cannot figure out how to tell the compiler where the libraries are. For example, -Wl,-rpath=${STAGING_DIR}/staging_dir/target-mips_24kc_musl/usr/lib
should add that directory to the library search path and enable the linker to find the JSON-C library, but I'm still getting a link error about that library:
$ ls ${STAGING_DIR}/target-mips_24kc_musl/usr/lib/libjson-c*
/mnt/kernel/openwrt/staging_dir/target-mips_24kc_musl/usr/lib/libjson-c.a
/mnt/kernel/openwrt/staging_dir/target-mips_24kc_musl/usr/lib/libjson-c.so
/mnt/kernel/openwrt/staging_dir/target-mips_24kc_musl/usr/lib/libjson-c.so.5
/mnt/kernel/openwrt/staging_dir/target-mips_24kc_musl/usr/lib/libjson-c.so.5.1.0
$ mips-openwrt-linux-musl-gcc -O3 -Wall -Wextra -Wcast-align -o fdfd -I${STAGING_DIR}/target-mips_24kc_musl/usr/include -I${BUILDROOT}/libsavl *.c -Wl,-rpath=${STAGING_DIR}/target-mips_24kc_musl/usr/lib -ljson-c -lsavl -ldl
/mnt/kernel/openwrt/staging_dir/toolchain-mips_24kc_gcc-8.4.0_musl/bin/../lib/gcc/mips-openwrt-linux-musl/8.4.0/../../../../mips-openwrt-linux-musl/bin/ld: cannot find -ljson-c
/mnt/kernel/openwrt/staging_dir/toolchain-mips_24kc_gcc-8.4.0_musl/bin/../lib/gcc/mips-openwrt-linux-musl/8.4.0/../../../../mips-openwrt-linux-musl/bin/ld: cannot find -lsavl
collect2: error: ld returned 1 exit status
(The error about -lsavl
is expected.)
What in the world is the correct syntax to tell the cross compiler where to look for libraries?
Thanks!