c - 链接时未定义的引用错误
问题描述
Linux debian 32 位主机 PC。项目包含源代码和预构建的工具链,目标是 ARM。当我尝试运行make
构建固件映像时,显示的错误很少undefined reference
,编译停止。
... ...
if [ -f pppd/Makefile.cyt ]; then \
make -C pppd -f Makefile.cyt; \
else \
make -C pppd; \
fi
make[3]: Entering directory '/home/roleyf/test/payton_1.4.1.SR1_gpl/payton/src/router/open_source/pkgs/pppd-2.4.1'
make -C pppd
make[4]: Entering directory '/home/roleyf/test/payton_1.4.1.SR1_gpl/payton/src/router/open_source/pkgs/pppd-2.4.1/pppd'
/opt/emlix/pnx8181/bin/arm-linux-gnueabi-gcc -O2 -pipe -Wall -D__linux__=1 -DHAVE_PATHS_H -DHAVE_MMAP -I../include -I/home/roleyf/test/payton_1.4.1.SR1_gpl/payton/src/router/open_source/include -DCHAPMS=1 -DMPPE=1 -DHAVE_CRYPT_H=1 -DUSE_CRYPT=1 -DPLUGIN -DCBCP_SUPPORT -Wl,-E -o pppd main.o magic.o fsm.o lcp.o ipcp.o upap.o chap-new.o md5.o ccp.o ecp.o auth.o options.o demand.o utils.o sys-linux.o ipxcp.o tty.o eap.o chap-md5.o md4.o chap_ms.o sha1.o pppcrypt.o cbcp.o -ldl
auth.o: In function `check_passwd':
auth.c:(.text+0x1d00): undefined reference to `crypt'
auth.c:(.text+0x1e2c): undefined reference to `crypt'
pppcrypt.o: In function `DesDecrypt':
pppcrypt.c:(.text+0xfc): undefined reference to `encrypt'
pppcrypt.o: In function `DesEncrypt':
pppcrypt.c:(.text+0x158): undefined reference to `encrypt'
pppcrypt.o: In function `DesSetkey':
pppcrypt.c:(.text+0x230): undefined reference to `setkey'
collect2: ld returned 1 exit status
Makefile:226: recipe for target 'pppd' failed
make[4]: *** [pppd] Error 1
make[4]: Leaving directory '/home/roleyf/test/payton_1.4.1.SR1_gpl/payton/src/router/open_source/pkgs/pppd-2.4.1/pppd'
Makefile.cyt:18: recipe for target 'all' failed
make[3]: *** [all] Error 2
make[3]: Leaving directory '/home/roleyf/test/payton_1.4.1.SR1_gpl/payton/src/router/open_source/pkgs/pppd-2.4.1'
/home/roleyf/test/payton_1.4.1.SR1_gpl/payton/src/Rules.mk:74: recipe for target '_subdir_pppd' failed
make[2]: *** [_subdir_pppd] Error 2
make[2]: Leaving directory '/home/roleyf/test/payton_1.4.1.SR1_gpl/payton/src/router/open_source'
/home/roleyf/test/payton_1.4.1.SR1_gpl/payton/src/Rules.mk:74: recipe for target '_subdir_open_source' failed
make[1]: *** [_subdir_open_source] Error 2
make[1]: Leaving directory '/home/roleyf/test/payton_1.4.1.SR1_gpl/payton/src/router'
Rules.mk:74: recipe for target '_subdir_router' failed
make: *** [_subdir_router] Error 2
'pppd' 子目录的Makefile 。我认为这是链接错误,pppd 子模块中的 Makefile 由于某种原因找不到libcrypt
库。这个问题看起来像一个间歇性错误,它不规则、随机地发生。有时编译允许我构建一个模块,但更多时候它不允许。如何解决这个问题?
解决方案
我解决了这个问题,问题是 Makefile 有代码(第 138 行),它在我的构建 PC(没有这些库)上的 /usr/lib 下的错误位置寻找 libcrypt*.* 库,而不是包含的工具链在压缩包中。我修改了这一行:
ifneq ($(wildcard /usr/lib/libcrypt*.*),)
至
ifneq ($(shell find ../.. -name libcrypt*.*),)
修改后,Makefile 找到了库并相应地设置了 LIBS。
推荐阅读
- excel - 在 vba 中,“On Error GoTo”语句不起作用。编译器在语句后给出错误
- sql - 如何获取日期范围之间的所有日期(包括 start_date 和 end_date)
- c# - 是否有可能在源代码中抑制 sonarcloud 的警告?
- excel - 字符串中的通配符
- docker - 为什么dockerfile中的添加或复制命令不添加新文件
- jenkins - 在 Jenkins 管道中运行并行 kubernetes 作业
- c++ - C++ 程序行为异常
- django - Django - 在文本字段中搜索另一个模型中包含的单词或短语
- docker - 在 Centos7 上运行 docker 时的权限
- kubernetes - 服务是否首先将流量发送到本地 pod?