arm 的 aarch64-linux-gnu-gcc 交叉编译器失败

aarch64-linux-gnu-gcc Cross Complier for arm fails

./configure --host=arm-elf-linux  CC=aarch64-linux-gnu-gcc --disable-sdl --disable-ffmpeg --disable-v4l2 --disable-openh264 --disable-libwebrtc --disable-libyuv

make dep && make

"文件格式错误" 错误:

$ file main.o 
main.o: ELF 64-bit LSB relocatable, x86-64,

$file other *.o
sip_uri.o: ELF 64-bit LSB relocatable, ARM aarch64,

所以 main.o 文件格式是 x86-64 ,但是其他 .o 文件格式是 ARM aarch64

但是....我仍然不知道如何解决(更改 main.o 文件格式)

Makefile 中 main.o 的段,我确定问题在 line:287

# Defines for building pjsua2-test application
161 #
162 export PJSUA2_TEST_SRCDIR = ../src/pjsua2-test
163 export PJSUA2_TEST_OBJS += $(OS_OBJS) $(M_OBJS) $(CC_OBJS) $(HOST_OBJS) \
164          main.o
165 export PJSUA2_TEST_CFLAGS += $(_CFLAGS) $(PJ_VIDEO_CFLAGS)
166 export PJSUA2_TEST_CXXFLAGS = $(_CXXFLAGS) $(PJSUA2_LIB_CFLAGS) $(PJ_VIDEO_CFLAGS)
167 export PJSUA2_TEST_LDFLAGS += $(PJ_LDXXFLAGS) $(PJ_LDXXLIBS) $(LDFLAGS)
168 ifeq ($(EXCLUDE_APP),0)
169 export PJSUA2_TEST_EXE := pjsua2-test-$(TARGET_NAME)$(HOST_EXE)
170 endif
171 export CC_OUT CC AR RANLIB HOST_MV HOST_RM HOST_RMDIR HOST_MKDIR OBJEXT LD LDOUT
----------------------
pjsua2-test: $(PJSUA2_TEST_EXE)
281 $(PJSUA2_TEST_EXE): $(PJSIP_LIB) $(PJSIP_SONAME)
282 $(PJSUA2_TEST_EXE): $(PJSIP_UA_LIB) $(PJSIP_UA_SONAME)
283 $(PJSUA2_TEST_EXE): $(PJSIP_SIMPLE_LIB) $(PJSIP_SIMPLE_SONAME)
284 $(PJSUA2_TEST_EXE): $(PJSUA_LIB_LIB) $(PJSUA_LIB_SONAME)
285 $(PJSUA2_TEST_EXE): $(PJSUA2_LIB_LIB) $(PJSUA2_LIB_SONAME)
286 $(PJSUA2_TEST_EXE):
287   **$(MAKE) -f $(RULES_MAK) APP=PJSUA2_TEST app=pjsua2-test $(subst /,$(HOST_PSEP),$(BINDIR)/$@)**

makefile 错误消息

mkdir -p output/pjsua2-test-aarch64-linux-gnu/
g++ -c  -DPJ_AUTOCONF=1 -g -O2    -Wall -DPJ_AUTOCONF=1 -O2 -DPJ_IS_BIG_ENDIAN=0 -DPJ_IS_LITTLE_ENDIAN=1    -I../include -I../../pjlib/include -I../../pjlib-util/include -I../../pjnath/include -I../../pjmedia/include -Wall -DPJ_AUTOCONF=1 -O2 -DPJ_IS_BIG_ENDIAN=0 -DPJ_IS_LITTLE_ENDIAN=1    -I../include -I../../pjlib/include -I../../pjlib-util/include -I../../pjnath/include -I../../pjmedia/include                                 \
    -o output/pjsua2-test-aarch64-linux-gnu/main.o \
    ../src/pjsua2-test/main.cpp
../src/pjsua2-test/main.cpp: In function ‘int main(int, char**)’:
../src/pjsua2-test/main.cpp:27:9: warning: division by zero [-Wdiv-by-zero]
   27 |    k = 1/0;
      |        ~^~
../src/pjsua2-test/main.cpp:26:7: warning: variable ‘k’ set but not used [-Wunused-but-set-variable]
   26 |   int k =1;
      |       ^
if test ! -d ../bin; then mkdir -p ../bin; fi
aarch64-linux-gnu-gcc -o ../bin/pjsua2-test-aarch64-linux-gnu \
     output/pjsua2-test-aarch64-linux-gnu/main.o -L/home/duma/Public/pjproject2/pjlib/lib -L/home/duma/Public/pjproject2/pjlib-util/lib -L/home/duma/Public/pjproject2/pjnath/lib -L/home/duma/Public/pjproject2/pjmedia/lib -L/home/duma/Public/pjproject2/pjsip/lib -L/home/duma/Public/pjproject2/third_party/lib              -lpjsua2-aarch64-linux-gnu -lstdc++ -lpjsua-aarch64-linux-gnu -lpjsip-ua-aarch64-linux-gnu -lpjsip-simple-aarch64-linux-gnu -lpjsip-aarch64-linux-gnu -lpjmedia-codec-aarch64-linux-gnu -lpjmedia-aarch64-linux-gnu -lpjmedia-videodev-aarch64-linux-gnu -lpjmedia-audiodev-aarch64-linux-gnu -lpjmedia-aarch64-linux-gnu -lpjnath-aarch64-linux-gnu -lpjlib-util-aarch64-linux-gnu  -lsrtp-aarch64-linux-gnu -lresample-aarch64-linux-gnu -lgsmcodec-aarch64-linux-gnu -lspeex-aarch64-linux-gnu -lilbccodec-aarch64-linux-gnu -lg7221codec-aarch64-linux-gnu  -lpj-aarch64-linux-gnu -lm -lrt -lpthread  
/usr/lib/gcc-cross/aarch64-linux-gnu/9/../../../../aarch64-linux-gnu/bin/ld: output/pjsua2-test-aarch64-linux-gnu/main.o: Relocations in generic ELF (EM: 62)
/usr/lib/gcc-cross/aarch64-linux-gnu/9/../../../../aarch64-linux-gnu/bin/ld: output/pjsua2-test-aarch64-linux-gnu/main.o: Relocations in generic ELF (EM: 62)
/usr/lib/gcc-cross/aarch64-linux-gnu/9/../../../../aarch64-linux-gnu/bin/ld: output/pjsua2-test-aarch64-linux-gnu/main.o: Relocations in generic ELF (EM: 62)
/usr/lib/gcc-cross/aarch64-linux-gnu/9/../../../../aarch64-linux-gnu/bin/ld: output/pjsua2-test-aarch64-linux-gnu/main.o: Relocations in generic ELF (EM: 62)
/usr/lib/gcc-cross/aarch64-linux-gnu/9/../../../../aarch64-linux-gnu/bin/ld: output/pjsua2-test-aarch64-linux-gnu/main.o: Relocations in generic ELF (EM: 62)
/usr/lib/gcc-cross/aarch64-linux-gnu/9/../../../../aarch64-linux-gnu/bin/ld: output/pjsua2-test-aarch64-linux-gnu/main.o: Relocations in generic ELF (EM: 62)
/usr/lib/gcc-cross/aarch64-linux-gnu/9/../../../../aarch64-linux-gnu/bin/ld: output/pjsua2-test-aarch64-linux-gnu/main.o: Relocations in generic ELF (EM: 62)
/usr/lib/gcc-cross/aarch64-linux-gnu/9/../../../../aarch64-linux-gnu/bin/ld: output/pjsua2-test-aarch64-linux-gnu/main.o: Relocations in generic ELF (EM: 62)
/usr/lib/gcc-cross/aarch64-linux-gnu/9/../../../../aarch64-linux-gnu/bin/ld: output/pjsua2-test-aarch64-linux-gnu/main.o: Relocations in generic ELF (EM: 62)
/usr/lib/gcc-cross/aarch64-linux-gnu/9/../../../../aarch64-linux-gnu/bin/ld: output/pjsua2-test-aarch64-linux-gnu/main.o: Relocations in generic ELF (EM: 62)
/usr/lib/gcc-cross/aarch64-linux-gnu/9/../../../../aarch64-linux-gnu/bin/ld: output/pjsua2-test-aarch64-linux-gnu/main.o: Relocations in generic ELF (EM: 62)
/usr/lib/gcc-cross/aarch64-linux-gnu/9/../../../../aarch64-linux-gnu/bin/ld: output/pjsua2-test-aarch64-linux-gnu/main.o: Relocations in generic ELF (EM: 62)
/usr/lib/gcc-cross/aarch64-linux-gnu/9/../../../../aarch64-linux-gnu/bin/ld: output/pjsua2-test-aarch64-linux-gnu/main.o: Relocations in generic ELF (EM: 62)
/usr/lib/gcc-cross/aarch64-linux-gnu/9/../../../../aarch64-linux-gnu/bin/ld: output/pjsua2-test-aarch64-linux-gnu/main.o: error adding symbols: file in wrong format
collect2: error: ld returned 1 exit status
make[2]: *** [/home/duma/Public/pjproject2/build/rules.mak:125: ../bin/pjsua2-test-aarch64-linux-gnu] Error 1
make[2]: Leaving directory '/home/duma/Public/pjproject2/pjsip/build'
make[1]: *** [Makefile:287: pjsua2-test-aarch64-linux-gnu] Error 2
make[1]: Leaving directory '/home/duma/Public/pjproject2/pjsip/build'
make: *** [Makefile:14: all] Error 1

link 的某些库可能不是使用相同的工具链构建的。您可以使用 objdump.

查看

示例(“文件格式”可能不是您的情况的准确结果):

$ aarch64-linux-gnu-objdump -TC libz.so

libz.so:     file format elf64-littleaarch64

请确认所有库的“文件格式”应该与您的工具链匹配。

更新:

make

时,您可以看到main.cpp的编译信息

g++ -c -DPJ_AUTOCONF=1 -g -O2 -Wall -DPJ_AUTOCONF=1 -O2 -DPJ_IS_BIG_ENDIAN=0 -DPJ_IS_LITTLE_ENDIAN=1 -I../include -I../../pjlib/include -I../../pjlib-util/include -I../../pjnath/include -I.. /../pjmedia/include -Wall -DPJ_AUTOCONF=1 -O2 -DPJ_IS_BIG_ENDIAN=0 -DPJ_IS_LITTLE_ENDIAN=1 -I../include -I../../pjlib/include -I../../pjlib-util/include -I../../pjnath/include -I../../pjmedia/include
-o output/pjsua2-test-aarch64-linux-gnu/main.o
../src/pjsua2-test/main.cpp

不应该是g++。应该是 aarch64-linux-gnu-g++.

请尝试以下步骤:

  1. 在配置命令行中添加CXX=aarch64-linux-gnu-g++并再次添加运行
  2. 确认您的 makefile 将使用 $(CXX) 来编译 cpp 文件,而不是 g++