首页 > 解决方案 > 链接时未定义的引用错误

问题描述

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库。这个问题看起来像一个间歇性错误,它不规则、随机地发生。有时编译允许我构建一个模块,但更多时候它不允许。如何解决这个问题?

标签: cmakefileshared-librarieslinker-errors

解决方案


我解决了这个问题,问题是 Makefile 有代码(第 138 行),它在我的构建 PC(没有这些库)上的 /usr/lib 下的错误位置寻找 libcrypt*.* 库,而不是包含的工具链在压缩包中。我修改了这一行:

ifneq ($(wildcard /usr/lib/libcrypt*.*),)

ifneq ($(shell find ../.. -name libcrypt*.*),)

修改后,Makefile 找到了库并相应地设置了 LIBS。


推荐阅读