【问题标题】:Undefined reference errors when linking链接时未定义的引用错误
【发布时间】:2019-06-12 21:59:44
【问题描述】:

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

Makefile 用于“pppd”子目录。我认为这是链接错误,由于某种原因,pppd 子模块中的 Makefile 找不到 libcrypt 库。这个问题看起来像一个间歇性错误,它不规则、随机地发生。有时编译允许我构建一个模块,但更多时候它不允许。如何解决这个问题?

【问题讨论】:

  • 是的,这是一个链接错误。作为 Linux 手册页,例如cryptencrypt and setkey 应该告诉你,你需要链接到 crypt 库。除非您在构建配置中犯了错误,否则需要引起项目维护者的注意。
  • 您的 makefile 正在寻找 /usr/include/crypt.h 以确定是否安装了 libcrypt。也许您需要安装它?
  • 强烈建议发布makefile的内容。

标签: c makefile shared-libraries linker-errors


【解决方案1】:

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

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

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

修改后,Makefile 定位到库并相应设置 LIBS。

【讨论】:

    猜你喜欢
    • 2015-01-23
    • 2014-04-21
    • 2013-03-15
    • 2023-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-04
    • 2016-06-10
    相关资源
    最近更新 更多