C++ cross compilation support

Hi,

I need to build my C++ software package in openwrt on a PPC64 based box. How can i compile my code. I only see gcc toolchain to cross-compile but not for any c++ code.

thanks in adavance!!

The default cross toolchain is able to build C++ just fine. What specific problem did you encounter?

1 Like

I compiled using SDK and it does not have uclicxx & libstdcxx. ERROR is below:

/home/user/jdixit/openwrt-sdk-cygwp_t1042_gcc-5.5.0_glibc.Linux-x86_64/staging_dir/toolchain-powerpc64_e5500_gcc-5.5.0_glibc/bin/../lib/gcc/powerpc64-openwrt-linux-gnu/5.5.0/../../../../powerpc64-openwrt-linux-gnu/bin/ld: helloworld.o: error adding symbols: file in wrong format
collect2: error: ld returned 1 exit status
Makefile:28: recipe for target 'helloworld' failed
make[3]: *** [helloworld] Error 1

The uclibc++ library is optional and needs to be install from feeds first:

./scripts/feeds update
./scripts/feeds install uclibcxx
make package/uclibc++/compile

The libstdc++ is part of the toolchain but might not be packaged by default. You can enable it menuconfig (Base System --> <M> libstdcpp) and stage it using make package/toolchain/compile

error adding symbols: file in wrong format
collect2: error: ld returned 1 exit status
Makefile:28: recipe for target 'helloworld' failed
make[3]: *** [helloworld] Error 1

Make sure that your source directory is clean and does not contain precompiled object files for other architectures.

2 Likes

If you are building on a PPC64 host, you can't use the precompiled/ downloadable SDK, which is for x86_64/ linux only, but must build your own toolchain from source.

1 Like

Hi,
After making following changing in Makefile of the custom package:

define Build/Compile
        $(MAKE) -C $(PKG_BUILD_DIR) \
        LIBS="-nodefaultlibs -lgcc -lc -lstdc++" \
        CXX="$(TARGET_CXX)" \
        CXXFLAGS="$(TARGET_CXXFLAGS) $(EXTRA_CPPFLAGS) -nostdinc++" \
        LDFLAGS="$(TARGET_LDFLAGS)"
endef

Now, we are getting following error:

Package helloworldcpp is missing dependencies for the following libraries:
libstdc++.so.6
Makefile:66: recipe for target '/home/user/jdixit/openwrt-sdk-cygwp_t1042_gcc-5.5.0_glibc.Linux-x86_64/bin/packages/powerpc64_e5500/base/helloworldcpp_1_powerpc64_e5500.ipk' failed

Your package Makefile now needs a DEPENDS:=+libstdcpp

2 Likes

Okay..thanks for point it out!!
can you please share a simple C++ Makefile (package Makefile), To refer. Because i need -std=c++11 and -pthread

Use TARGET_CFLAGS += -std=c++11 -pthread .

The -pthread flag might be redundant because musl libc has pthread support built into the core library, you don't need any extra linker flags.

Thanks you Jow!! :slight_smile:
i will try and let you know if any issue!!

Using the Makefile from section 4.3 of the following blog, I'm able to compile pmacct up to version 1.7.5
http://dvblog.soabit.com/building-custom-openwrt-packages-an-hopefully-complete-guide/

However in v1.7.6, external dependencies were added:

EDIT since I realized I was failing much earlier in the build.

Here's my current Makefile:

#
# Copyright (C) 2006 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#

include $(TOPDIR)/rules.mk

PKG_NAME:=pmacct
PKG_VERSION:=1.7.6
PKG_RELEASE:=1

PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=http://www.pmacct.net/ 
PKG_HASH:=aa4407fe552412f56790ef1b8fde01a53e80136488c89f91e43c84825f1357f3
PKG_MAINTAINER:=Damiano Verzulli <damiano@verzulli.it>
PKG_LICENSE:=GPL-2.0

PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)

PKG_FIXUP:=autoreconf

PKG_INSTALL:=1
PKG_BUILD_PARALLEL:=1

include $(INCLUDE_DIR)/package.mk

CONFIGURE_ARGS += \
	--with-pcap-includes="$(STAGING_DIR)/usr/include" \
	--with-pcap-libs="$(STAGING_DIR)/usr/lib" \
	--enable-bgp-bins=no \
	--enable-bmp-bins=no \
	--enable-st-bins=no

TARGET_CFLAGS += -ffunction-sections -fdata-sections
TARGET_LDFLAGS += -Wl,--gc-sections


define Package/pmacct
  SECTION:=net
  CATEGORY:=Network
  DEPENDS:=+libpcap +libpthread +libstdcpp
  TITLE:=a powerful IP accounting set of tools
  URL:=http://www.pmacct.net/
endef

define Package/pmacct/install	
	$(INSTALL_DIR) $(1)/usr/sbin
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/src/pmacct $(1)/usr/sbin/
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/src/pmacctd $(1)/usr/sbin/
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/src/sfacctd $(1)/usr/sbin/
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/src/nfacctd $(1)/usr/sbin/
endef

$(eval $(call BuildPackage,pmacct))

Which results in the following build error:

/bin/bash ../../libtool  --tag=CC   --mode=link arm-openwrt-linux-muslgnueabi-gcc -DFLOW_SPLAY -DEXPIRY_RB -I./..  -O2 -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/build/openwrt/build_dir/target-arm_cortex-a15+neon-vfpv4_musl_eabi/pmacct-1.7.6=pmacct-1.7.6 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro -ffunction-sections -fdata-sections  -I/home/build/openwrt/build_dir/target-arm_cortex-a15+neon-vfpv4_musl_eabi/pmacct-1.7.6/src/external_libs/rootfs/include  -I/home/build/openwrt/staging_dir/target-arm_cortex-a15+neon-vfpv4_musl_eabi/usr/include  -I/home/build/openwrt/build_dir/target-arm_cortex-a15+neon-vfpv4_musl_eabi/pmacct-1.7.6/src  -L/home/build/openwrt/build_dir/target-arm_cortex-a15+neon-vfpv4_musl_eabi/pmacct-1.7.6/src/external_libs/rootfs/lib -L/home/build/openwrt/staging_dir/toolchain-arm_cortex-a15+neon-vfpv4_gcc-8.4.0_musl_eabi/usr/lib -L/home/build/openwrt/staging_dir/toolchain-arm_cortex-a15+neon-vfpv4_gcc-8.4.0_musl_eabi/lib -znow -zrelro -Wl,--gc-sections  -o libnfprobe_plugin.la  libnfprobe_plugin_la-nfprobe_plugin.lo libnfprobe_plugin_la-netflow5.lo libnfprobe_plugin_la-netflow9.lo libnfprobe_plugin_la-convtime.lo  -lcdada -lstdc++ -lpcap  -ldl -L/home/build/openwrt/staging_dir/target-arm_cortex-a15+neon-vfpv4_musl_eabi/usr/lib -lm -lpthread
/home/build/openwrt/staging_dir/target-arm_cortex-a15+neon-vfpv4_musl_eabi/../host/bin/grep: /builder/shared-workdir/build/staging_dir/toolchain-arm_cortex-a15+neon-vfpv4_gcc-8.4.0_musl_eabi/arm-openwrt-linux-muslgnueabi/lib/libstdc++.la: No such file or directory
/home/build/openwrt/staging_dir/target-arm_cortex-a15+neon-vfpv4_musl_eabi/../host/bin/sed: can't read /builder/shared-workdir/build/staging_dir/toolchain-arm_cortex-a15+neon-vfpv4_gcc-8.4.0_musl_eabi/arm-openwrt-linux-muslgnueabi/lib/libstdc++.la: No such file or directory
OpenWrt-libtool: link: `/builder/shared-workdir/build/staging_dir/toolchain-arm_cortex-a15+neon-vfpv4_gcc-8.4.0_musl_eabi/arm-openwrt-linux-muslgnueabi/lib/libstdc++.la' is not a valid libtool archive
make[6]: *** [Makefile:396: libnfprobe_plugin.la] Error 1
make[6]: Leaving directory '/home/build/openwrt/build_dir/target-arm_cortex-a15+neon-vfpv4_musl_eabi/pmacct-1.7.6/src/nfprobe_plugin'
make[5]: *** [Makefile:1288: all-recursive] Error 1
make[5]: Leaving directory '/home/build/openwrt/build_dir/target-arm_cortex-a15+neon-vfpv4_musl_eabi/pmacct-1.7.6/src'
make[4]: *** [Makefile:631: all] Error 2
make[4]: Leaving directory '/home/build/openwrt/build_dir/target-arm_cortex-a15+neon-vfpv4_musl_eabi/pmacct-1.7.6/src'
make[3]: *** [Makefile:735: all-recursive] Error 1
make[3]: Leaving directory '/home/build/openwrt/build_dir/target-arm_cortex-a15+neon-vfpv4_musl_eabi/pmacct-1.7.6'
make[2]: *** [Makefile:59: /home/build/openwrt/build_dir/target-arm_cortex-a15+neon-vfpv4_musl_eabi/pmacct-1.7.6/.built] Error 2
make[2]: Leaving directory '/home/build/openwrt/bin/repo/pmacct'
time: package/feeds/repo/pmacct/compile#39.98#12.14#48.97
    ERROR: package/feeds/repo/pmacct failed to build.
make[1]: *** [package/Makefile:114: package/feeds/repo/pmacct/compile] Error 1
make[1]: Leaving directory '/home/build/openwrt'
make: *** [/home/build/openwrt/include/toplevel.mk:223: package/pmacct/compile] Error 2

config.log posted here: https://pastebin.com/a4pbWuKD

I also tried building with the --without-external-deps flag added to the Makefile, but since libcdada is not included in OpenWrt, that's not going to work.

P.S. The following Docker container was utilized to make these tests:
openwrtorg/sdk:ipq806x-generic-21.02-SNAPSHOT

Well I'm as perplexed as the user in this thread: https://www.linuxquestions.org/questions/linux-from-scratch-13/lfs-6-14-gmp-6-1-0-libtool-error-libstdc-ls-is-not-a-valid-libtool-archive-4175586676/

However I ran the commands below and now the package builds.

cd /home/build/openwrt/staging_dir/toolchain-arm_cortex-a15+neon-vfpv4_gcc-8.4.0_musl_eabi/lib/
mv libstdc++.la libstdc++.old

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.