Hi all, I am trying to cross-compile my C++ program for Openwrt using SDK (openwrt-sdk-mvebu-cortexa9_gcc-8.3.0_musl_eabi.Linux-x86_64 for my Linksys WRT 1900ACS). The program is compiled with both dynamic-linked library (libpcap, libcurl and libpthread) and static-linked library( libPacket++,libPcap+ and libCommon++ from pcapplusplus project; libfaup_static from faup project). (I static link these libeary because they don't exsit in openwrt.) The compliation errors seems to suggest the static-linking isn't working. I wonder how could I properly do dynamic and static linking here? thanks!
Specifically, the compliation error is
make[1]: Entering directory '/home/hangguo/openwrt-sdk-mvebu-cortexa9_gcc-8.3.0_musl_eabi.Linux-x86_64'
make[2]: Entering directory '/home/hangguo/openwrt-sdk-mvebu-cortexa9_gcc-8.3.0_musl_eabi.Linux-x86_64'
make[3]: Entering directory '/home/hangguo/openwrt-sdk-mvebu-cortexa9_gcc-8.3.0_musl_eabi.Linux-x86_64/package/toolchain'
Makefile:802: WARNING: skipping libgomp -- package has no install section
echo "libc" >> /home/hangguo/openwrt-sdk-mvebu-cortexa9_gcc-8.3.0_musl_eabi.Linux-x86_64/staging_dir/target-arm_cortex-a9+vfpv3_musl_eabi/pkginfo/toolchain.default.install
echo "libgcc" >> /home/hangguo/openwrt-sdk-mvebu-cortexa9_gcc-8.3.0_musl_eabi.Linux-x86_64/staging_dir/target-arm_cortex-a9+vfpv3_musl_eabi/pkginfo/toolchain.default.install
echo "libpthread" >> /home/hangguo/openwrt-sdk-mvebu-cortexa9_gcc-8.3.0_musl_eabi.Linux-x86_64/staging_dir/target-arm_cortex-a9+vfpv3_musl_eabi/pkginfo/toolchain.default.install
touch -r /home/hangguo/openwrt-sdk-mvebu-cortexa9_gcc-8.3.0_musl_eabi.Linux-x86_64/build_dir/target-arm_cortex-a9+vfpv3_musl_eabi/toolchain/.built /home/hangguo/openwrt-sdk-mvebu-cortexa9_gcc-8.3.0_musl_eabi.Linux-x86_64/build_dir/target-arm_cortex-a9+vfpv3_musl_eabi/toolchain/.autoremove 2>/dev/null >/dev/null
find /home/hangguo/openwrt-sdk-mvebu-cortexa9_gcc-8.3.0_musl_eabi.Linux-x86_64/build_dir/target-arm_cortex-a9+vfpv3_musl_eabi/toolchain -mindepth 1 -maxdepth 1 -not '(' -type f -and -name '.*' -and -size 0 ')' -and -not -name '.pkgdir' | xargs -r rm -rf
make[3]: Leaving directory '/home/hangguo/openwrt-sdk-mvebu-cortexa9_gcc-8.3.0_musl_eabi.Linux-x86_64/package/toolchain'
time: package/toolchain/compile#0.24#0.10#0.29
make[3]: Entering directory '/home/hangguo/openwrt-sdk-mvebu-cortexa9_gcc-8.3.0_musl_eabi.Linux-x86_64/package/iotsteed'
rm -f /home/hangguo/openwrt-sdk-mvebu-cortexa9_gcc-8.3.0_musl_eabi.Linux-x86_64/build_dir/target-arm_cortex-a9+vfpv3_musl_eabi/iotsteed/.built
touch /home/hangguo/openwrt-sdk-mvebu-cortexa9_gcc-8.3.0_musl_eabi.Linux-x86_64/build_dir/target-arm_cortex-a9+vfpv3_musl_eabi/iotsteed/.built_check
CFLAGS="-Os -pipe -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -mfloat-abi=hard -ffile-prefix-map=/home/hangguo/openwrt-sdk-mvebu-cortexa9_gcc-8.3.0_musl_eabi.Linux-x86_64/build_dir/target-arm_cortex-a9+vfpv3_musl_eabi/iotsteed=iotsteed -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro " LDFLAGS="" LIBS="-Wl, -Bdynamic -lpcap -lcurl -lpthread -Wl, -Bstatic -lPacket++ -lPcap++ -lCommon++ -lfaup_static" make -C /home/hangguo/openwrt-sdk-mvebu-cortexa9_gcc-8.3.0_musl_eabi.Linux-x86_64/build_dir/target-arm_cortex-a9+vfpv3_musl_eabi/iotsteed AR="arm-openwrt-linux-muslgnueabi-gcc-ar" AS="arm-openwrt-linux-muslgnueabi-gcc -c -Os -pipe -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -mfloat-abi=hard -ffile-prefix-map=/home/hangguo/openwrt-sdk-mvebu-cortexa9_gcc-8.3.0_musl_eabi.Linux-x86_64/build_dir/target-arm_cortex-a9+vfpv3_musl_eabi/iotsteed=iotsteed -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro" LD=arm-openwrt-linux-muslgnueabi-ld NM="arm-openwrt-linux-muslgnueabi-gcc-nm" CC="arm-openwrt-linux-muslgnueabi-gcc" GCC="arm-openwrt-linux-muslgnueabi-gcc" CXX="arm-openwrt-linux-muslgnueabi-g++" RANLIB="arm-openwrt-linux-muslgnueabi-gcc-ranlib" STRIP=arm-openwrt-linux-muslgnueabi-strip OBJCOPY=arm-openwrt-linux-muslgnueabi-objcopy OBJDUMP=arm-openwrt-linux-muslgnueabi-objdump SIZE=arm-openwrt-linux-muslgnueabi-size CROSS="arm-openwrt-linux-muslgnueabi-" CXXFLAGS="-Os -pipe -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -mfloat-abi=hard -ffile-prefix-map=/home/hangguo/openwrt-sdk-mvebu-cortexa9_gcc-8.3.0_musl_eabi.Linux-x86_64/build_dir/target-arm_cortex-a9+vfpv3_musl_eabi/iotsteed=iotsteed -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro " ARCH="arm" iotsteed;
make[4]: Entering directory '/home/hangguo/openwrt-sdk-mvebu-cortexa9_gcc-8.3.0_musl_eabi.Linux-x86_64/build_dir/target-arm_cortex-a9+vfpv3_musl_eabi/iotsteed'
arm-openwrt-linux-muslgnueabi-g++ -Os -pipe -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -mfloat-abi=hard -ffile-prefix-map=/home/hangguo/openwrt-sdk-mvebu-cortexa9_gcc-8.3.0_musl_eabi.Linux-x86_64/build_dir/target-arm_cortex-a9+vfpv3_musl_eabi/iotsteed=iotsteed -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro -c -o main.o main.cc
In file included from tests.h:5,
from main.cc:4:
iotsteed.h:11:10: fatal error: pcapplusplus/Packet.h: No such file or directory
#include <pcapplusplus/Packet.h>
^~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
<builtin>: recipe for target 'main.o' failed
make[4]: *** [main.o] Error 1
make[4]: Leaving directory '/home/hangguo/openwrt-sdk-mvebu-cortexa9_gcc-8.3.0_musl_eabi.Linux-x86_64/build_dir/target-arm_cortex-a9+vfpv3_musl_eabi/iotsteed'
Makefile:47: recipe for target '/home/hangguo/openwrt-sdk-mvebu-cortexa9_gcc-8.3.0_musl_eabi.Linux-x86_64/build_dir/target-arm_cortex-a9+vfpv3_musl_eabi/iotsteed/.built' failed
make[3]: *** [/home/hangguo/openwrt-sdk-mvebu-cortexa9_gcc-8.3.0_musl_eabi.Linux-x86_64/build_dir/target-arm_cortex-a9+vfpv3_musl_eabi/iotsteed/.built] Error 2
make[3]: Leaving directory '/home/hangguo/openwrt-sdk-mvebu-cortexa9_gcc-8.3.0_musl_eabi.Linux-x86_64/package/iotsteed'
time: package/iotsteed/compile#0.24#0.11#0.30
package/Makefile:111: recipe for target 'package/iotsteed/compile' failed
make[2]: *** [package/iotsteed/compile] Error 2
make[2]: Leaving directory '/home/hangguo/openwrt-sdk-mvebu-cortexa9_gcc-8.3.0_musl_eabi.Linux-x86_64'
package/Makefile:107: recipe for target '/home/hangguo/openwrt-sdk-mvebu-cortexa9_gcc-8.3.0_musl_eabi.Linux-x86_64/staging_dir/target-arm_cortex-a9+vfpv3_musl_eabi/stamp/.package_compile' failed
make[1]: *** [/home/hangguo/openwrt-sdk-mvebu-cortexa9_gcc-8.3.0_musl_eabi.Linux-x86_64/staging_dir/target-arm_cortex-a9+vfpv3_musl_eabi/stamp/.package_compile] Error 2
make[1]: Leaving directory '/home/hangguo/openwrt-sdk-mvebu-cortexa9_gcc-8.3.0_musl_eabi.Linux-x86_64'
/home/hangguo/openwrt-sdk-mvebu-cortexa9_gcc-8.3.0_musl_eabi.Linux-x86_64/include/toplevel.mk:218: recipe for target 'world' failed
make: *** [world] Error 2
my package manifest file is
include $(TOPDIR)/rules.mk
PKG_NAME:=iotsteed
PKG_RELEASE:=1
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
include $(INCLUDE_DIR)/package.mk
define Package/iotsteed
SECTION:=utils
CATEGORY:=Utilities
TITLE:= IoTSTEED: IoT traffic monitor
DEPENDS:=+libstdcpp +libgcc +libpcap +libcurl +libpthread
endef
define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)
$(CP) ./src/* $(PKG_BUILD_DIR)/
endef
TARGET_LIBS = -Wl, -Bdynamic -lpcap -lcurl -lpthread \
-Wl, -Bstatic -lPacket++ -lPcap++ -lCommon++ -lfaup_static
define Build/Compile
CFLAGS="$(TARGET_CFLAGS) $(EXTRA_CPPFLAGS) " \
LDFLAGS="$(EXTRA_LDFLAGS)" \
LIBS="$(TARGET_LIBS)" \
$(MAKE) -C $(PKG_BUILD_DIR) \
$(TARGET_CONFIGURE_OPTS) \
CROSS="$(TARGET_CROSS)" \
CXXFLAGS="$(TARGET_CFLAGS) $(EXTRA_CPPFLAGS) " \
ARCH="$(ARCH)" \
$(1);
endef
define Package/iotsteed/install
$(INSTALL_DIR) $(1)/bin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/iotsteed $(1)/bin/
endef
$(eval $(call BuildPackage,iotsteed))
and my src/Makefile is
SRCS = main.cc iotsteed.cc tests.cc det.cc sln.cc
OBJS = $(SRCS:.cc=.o)
.PHONY : clean
iotsteed: $(OBJS)
$(CXX) $(CXXFLAGS) -o iotsteed $(OBJS) $(LIBS)
main.o: dev.h dg_node.h det.h tests.h iotsteed.h version.h debug.h
iotsteed.o: dg_node.h det.h iotsteed.h dev.h sln.h debug.h
tests.o: dev.h dg_node.h det.h tests.h iotsteed.h svr.h debug.h
det.o: dg_node.h det.h debug.h
sln.o: svr.h sln.h debug.h
clean :
rm -f iotsteed $(OBJS)