解决错误 undefined reference to symbol '__cxa_throw_bad_array_new_length@@CXXABI_1.3.8'
1. 错误信息
在Makefile里,定义CC为"aarch64-linux-gnu-g++ --sysroot=$(MPSOC_ROOTFS)",编译test.cpp,没有错误。如果使用environment-setup-aarch64-xilinx-linux里的设置,在Makefile里不定义CC,编译test.cpp出现下列错误。
hankf@xszgs4:/proj/hankf/zcu106/v183/egl$ make aarch64-xilinx-linux-gcc --sysroot=/opt/petalinux/2018.3/zcu106bspsdk/sysroots/aarch64-xilinx-linux -c test.cpp -O2 -pipe -g -feliminate-unused-debug-types -g -Wall -O2 -Wall -fpic -fpermissive -I =/usr/include -I =/usr/include/drm -I =/usr/include/libdrm -I =/usr/src/debug/libdrm/2.4.83-r0/libdrm-2.4.83 -I =/usr/src/debug/libdrm/2.4.83-r0/libdrm-2.4.83 -I =/usr/src/debug/libdrm/2.4.83-r0/libdrm-2.4.83/tests -o test.o aarch64-xilinx-linux-gcc --sysroot=/opt/petalinux/2018.3/zcu106bspsdk/sysroots/aarch64-xilinx-linux -o egl test.o -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -L =/usr/lib/ -lpthread -ldl -lrt -Wl,-rpath-link, -Wl,-O1 -Wl,--hash-style=gnu -Wl,--allow-multiple-definition -ldrm -lm -lEGL /opt/petalinux/2018.3/zcu106bspsdk/sysroots/x86_64-petalinux-linux/usr/libexec/aarch64-xilinx-linux/gcc/aarch64-xilinx-linux/7.3.0/real-ld: test.o: undefined reference to symbol '__cxa_throw_bad_array_new_length@@CXXABI_1.3.8' /opt/petalinux/2018.3/zcu106bspsdk/sysroots/aarch64-xilinx-linux/usr/lib/libstdc++.so.6: error adding symbols: DSO missing from command line collect2: error: ld returned 1 exit status Makefile:26: recipe for target 'egl' failed make: *** [egl] Error 1
2. 编译器信息
在Makefile里,使用编译器aarch64-linux-gnu-g++。
在environment-setup-aarch64-xilinx-linux里,定义CC为"aarch64-xilinx-linux-gcc --sysroot=$SDKTARGETSYSROOT",使用编译器aarch64-xilinx-linux-gcc。
hankf@xszgs4:/proj/hankf/zcu106/v183/egl$ which aarch64-xilinx-linux-gcc /opt/petalinux/2018.3/zcu106bspsdk/sysroots/x86_64-petalinux-linux/usr/bin/aarch64-xilinx-linux/aarch64-xilinx-linux-gcc hankf@xszgs4:/proj/hankf/zcu106/v183/egl$ aarch64-xilinx-linux-gcc --version aarch64-xilinx-linux-gcc (GCC) 7.3.0 Copyright (C) 2017 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. hankf@xszgs4:/proj/hankf/zcu106/v183/egl$ which aarch64-xilinx-linux-g++ /opt/petalinux/2018.3/zcu106bspsdk/sysroots/x86_64-petalinux-linux/usr/bin/aarch64-xilinx-linux/aarch64-xilinx-linux-g++ hankf@xszgs4:/proj/hankf/zcu106/v183/egl$ aarch64-xilinx-linux-g++ --version aarch64-xilinx-linux-g++ (GCC) 7.3.0 Copyright (C) 2017 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. hankf@xszgs4:/proj/hankf/zcu106/v183/egl$ which aarch64-linux-gnu-gcc /xilinxtool/SDK/2018.3/gnu/aarch64/lin/aarch64-linux/bin/aarch64-linux-gnu-gcc hankf@xszgs4:/proj/hankf/zcu106/v183/egl$ aarch64-linux-gnu-gcc --version aarch64-linux-gnu-gcc (Linaro GCC 7.3-2018.04-rc3) 7.3.1 20180314 Copyright (C) 2017 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. hankf@xszgs4:/proj/hankf/zcu106/v183/egl$ which aarch64-linux-gnu-g++ /xilinxtool/SDK/2018.3/gnu/aarch64/lin/aarch64-linux/bin/aarch64-linux-gnu-g++ hankf@xszgs4:/proj/hankf/zcu106/v183/egl$ aarch64-linux-gnu-g++ --version aarch64-linux-gnu-g++ (Linaro GCC 7.3-2018.04-rc3) 7.3.1 20180314 Copyright (C) 2017 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
3. Makefile
SYSROOT=/xilinxtool/peta/2018.2/zcu106sdk/sysroots/aarch64-xilinx-linux MPSOC_ROOTFS=/xilinxtool/peta/2018.3/zcu106sdk/sysroots/aarch64-xilinx-linux CC = aarch64-linux-gnu-g++ --sysroot=$(MPSOC_ROOTFS) CFLAGS += -g -Wall -O2 -Wall -fpic -fpermissive CFLAGS += -I ${SYSROOT}/usr/include \ -I ${SYSROOT}/usr/include/drm \ -I ${SYSROOT}/usr/include/libdrm LDFLAGS += -L ${SYSROOT}/usr/lib/ -lpthread -ldl -lrt -Wl,-rpath-link, -Wl,-O1 -Wl,--hash-style=gnu LDFLAGS += -ldrm -lm -lEGL
4. 解决办法
在environment-setup-aarch64-xilinx-linux里, CC被定义成"aarch64-xilinx-linux-gcc --sysroot=SDKTARGETSYSROOT"。
而Makefile里使用gcc去编译cpp文件,导致错误。Makefile里,定义CC为“aarch64-linux-gnu-g++”,也不符合常规。
在Makefile里使用CXX去编译cpp文件,就没有这个问题,其中CXX被定义成"aarch64-xilinx-linux-g++ --sysroot=SDKTARGETSYSROOT"。
所以关键是使用aarch64-xilinx-linux-g++编译cpp文件。
付汉杰 hankf@amd.com