链接时存在未定义的参考错误

时间:2019-06-12 21:59:44

标签: c makefile shared-libraries linker-errors

Linux debian 32位主机。 项目包含源代码和预构建的工具链,目标是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

MakefileMakefile.linux我认为,这是链接错误,makefile可能会在构建PC的工具链目录中寻找libcrypt。我假设需要在代码中的某个位置指定标志,以配置/修复此标志。应该在哪里指定?

1 个答案:

答案 0 :(得分:0)

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

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

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

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