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文件。