问题1:交叉编译失败
Makefile:509:***warning No libdw.h found or old libdw.h found, disables dwarf support. Please install elfutils-devel/elfutils-dev
解决方法:
发现在Makefilel里面根据编译和链接一个测试程序来确认是否有elf相关的API。可以将小程序的c拷贝出来实验。
($(shell sh -c "(echo '\#include <dwarf.h>'; echo '\#include <libdw.h>'; echo 'int main(void) { Dwarf *dbg; dbg = dwarf_begin(0, DWARF_C_READ); return (long)dbg; }') | $(CC) -x c - $(ALL_CFLAGS) -o $(BITBUCKET) $(ALL_LDFLAGS) $(EXTLIBS) "$(QUIET_STDERR)" && echo y"), y)
手工拷贝编译上报如下错误:
<stdin>:1:20 error:libelf.h:No Such File or directory
在交叉编译工具下找文件:
find /opt/cross_tools -name elf.h
结果如下:/opt/croos_tools/... .../elf.h
于是将INCLUDE = -I /opt/croos_tools/... .../elf.h 加到CC里面
问题2:链接错误
:(.text+0x20):undefined reference to 'elf_begin'
解决方法:
grep -rn elf_begin /opt/croos_tools
结果如下: Binary file /opt/croos_tools/.. .../usr/lib/libelf/libelf.a matches
交叉编译器只有静态库
所以需要将
EXTLIBS = -lpthread -lrt -lelf -lm
增加后缀
EXTLIBS = -lpthread -lrt -lelf -lm -static -L. -lelf
问题3:路径找不到
c文件的.h找不到,需要将include <xxx.h>修改为"xxx.h",这一块需要研究
GCC编译过程与动态链接库和静态链接库
https://www.cnblogs.com/king-lps/p/7757919.html
Linux下gcc生成和使用静态库和动态库详解
https://blog.youkuaiyun.com/CSqingchen/article/details/51546784