今天使用64位toolchain编译工程时,发现,toolchain依赖的共享库不存在,编译报错:
1 2 3 | herbert@Lenovo:/work/migration$ aarch64-buildroot-linux-gnu-cc test.c ../libexec/gcc/aarch64-buildroot-linux-gnu/5.3.0/cc1: error while loading shared libraries: libmpc.so.3: cannot open shared object file: No such file or directory |
查看toolchain的ELF头信息:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | herbert@Lenovo:/work/migration$ readelf aarch64-buildroot-linux-gnu-cc -hELF Header: Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 Class: ELF32 Data: 2's complement, little endian Version: 1 (current) OS/ABI: UNIX - System V ABI Version: 0 Type: EXEC (Executable file) Machine: Intel 80386 Version: 0x1 Entry point address: 0x8048770 Start of program headers: 52 (bytes into file) Start of section headers: 5032 (bytes into file) Flags: 0x0 Size of this header: 52 (bytes) Size of program headers: 32 (bytes) Number of program headers: 8 Size of section headers: 40 (bytes) Number of section headers: 28 Section header string table index: 27 |
这个64位交叉编译器是32位的。而我的ubuntu系统是64位。使用ldd查看上述报错的cc1的依赖库:
1 2 3 4 5 6 7 8 9 10 11 | herbert@Lenovo:/work/migration$ ldd ../libexec/gcc/aarch64-buildroot-linux-gnu/5.3.0/cc1 linux-gate.so.1 => (0xf778c000) libmpc.so.3 => not found libmpfr.so.4 => not found libgmp.so.10 => not found libdl.so.2 => /lib32/libdl.so.2 (0xf776a000) libstdc++.so.6 => /usr/lib32/libstdc++.so.6 (0xf75f3000) libm.so.6 => /lib32/libm.so.6 (0xf759d000) libgcc_s.so.1 => /usr/lib32/libgcc_s.so.1 (0xf7580000) libc.so.6 => /lib32/libc.so.6 (0xf73cc000) /lib/ld-linux.so.2 (0x56563000) |
发现,依赖库找不到,然后定位 libmpc.so文件:
1 2 3 | herbert@Lenovo:/work/migration$ locate libmpc.so/usr/lib/x86_64-linux-gnu/libmpc.so.3/usr/lib/x86_64-linux-gnu/libmpc.so.3.0.0 |
发现,只有64位版本。
在64位ubuntu上,安装32位的包,只要在包后面加":i386"即可:
1 | herbert@Lenovo:/work/migration$ sudo apt-get install libmpc-dev:i386 |
安装后,能顺利编译。