前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >解决错误 undefined reference to symbol '__cxa_throw_bad_array_new_length@@CXXABI_1.3.8'

解决错误 undefined reference to symbol '__cxa_throw_bad_array_new_length@@CXXABI_1.3.8'

作者头像
hankfu
发布2020-07-17 09:33:01
2.7K0
发布2020-07-17 09:33:01
举报
文章被收录于专栏:hank

1. 错误信息

在Makefile里,定义CC为"aarch64-linux-gnu-g++ --sysroot=$(MPSOC_ROOTFS)",编译test.cpp,没有错误。如果使用environment-setup-aarch64-xilinx-linux里的设置,在Makefile里不定义CC,编译test.cpp出现下列错误。

代码语言:javascript
复制
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。

代码语言:javascript
复制
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

代码语言:javascript
复制
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文件。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019-10-31 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档