首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何修复对`nettle_sha256_digest`的未定义引用?

如何修复对`nettle_sha256_digest`的未定义引用?
EN

Stack Overflow用户
提问于 2017-11-15 22:35:27
回答 1查看 2.4K关注 0票数 1

TL;博士

我正在尝试构建一个使用这个依赖项的go项目:https://github.com/mqu/openldap,它反过来对外链接lldap和llber库,后者又使用lgnutls,它使用lnettle,这就是我陷入困境的地方。

go build生成一长串未定义的引用,生成失败。这是一个样本:

代码语言:javascript
复制
/usr/lib/x86_64-linux-gnu/libgnutls.a(sha-x86-ssse3.o): In function `_ctx_init':
(.text+0x468): undefined reference to `nettle_sha256_digest'
/usr/lib/x86_64-linux-gnu/libgnutls.a(sha-x86-ssse3.o): In function `_ctx_init':
(.text+0x476): undefined reference to `nettle_sha224_init'
/usr/lib/x86_64-linux-gnu/libgnutls.a(sha-x86-ssse3.o): In function `_ctx_init':
(.text+0x494): undefined reference to `nettle_sha256_init'
/usr/lib/x86_64-linux-gnu/libgnutls.a(sha-x86-ssse3.o): In function `_ctx_init':
(.text+0x4b8): undefined reference to `nettle_sha256_digest'
/usr/lib/x86_64-linux-gnu/libgnutls.a(sha-x86-ssse3.o): In function `_ctx_init':
(.text+0x4c6): undefined reference to `nettle_sha256_init'
/usr/lib/x86_64-linux-gnu/libgnutls.a(sha-x86-ssse3.o):(.data.rel.ro+0x18): undefined reference to `nettle_sha256_init'
/usr/lib/x86_64-linux-gnu/libgnutls.a(sha-x86-ssse3.o):(.data.rel.ro+0x28): undefined reference to `nettle_sha256_digest'
/usr/lib/x86_64-linux-gnu/libgnutls.a(sha-x86-ssse3.o):(.data.rel.ro+0x58): undefined reference to `nettle_sha224_init'
/usr/lib/x86_64-linux-gnu/libgnutls.a(sha-x86-ssse3.o):(.data.rel.ro+0x68): undefined reference to `nettle_sha224_digest'
/usr/lib/x86_64-linux-gnu/libgnutls.a(sha-x86-ssse3.o):(.data.rel.ro+0x98): undefined reference to `nettle_sha1_init'
/usr/lib/x86_64-linux-gnu/libgnutls.a(sha-x86-ssse3.o):(.data.rel.ro+0xa8): undefined reference to `nettle_sha1_digest'

我的go build命令:

代码语言:javascript
复制
CC=/usr/local/musl/bin/musl-gcc \
    GOOS=linux go build \
    -o /bin/activedirectory \
    -ldflags '-linkmode external -extldflags "-static -L/usr/lib/x86_64-linux-gnu -lnettle -lp11 -lsasl2 -lgnutls -ltasn1"'

我已经尝试通过安装libnettle4nettle-devlibghc-nettle-devnettle-bin来解决这个问题。我已经确保将-lnettle包含在in标志中。不走运。

更多上下文

openldap库链接代码中的ldaplber库:

代码语言:javascript
复制
package openldap

/*

#define LDAP_DEPRECATED 1
#include <stdlib.h>
#include <ldap.h>

static inline char* to_charptr(const void* s) { return (char*)s; }
static inline LDAPControl** to_ldapctrlptr(const void* s) {
    return (LDAPControl**) s;
}
*/
// #cgo CFLAGS: -DLDAP_DEPRECATED=1
// #cgo linux CFLAGS: -DLINUX=1
// #cgo LDFLAGS: -lldap -llber

这要求我安装并将您在构建命令中看到的所有库都包含在all标志中。

简而言之,依赖链是这样的:

-> lgnutls -> lnettle.

我添加了lgnutls,这解决了我的gnutls依赖问题,但我无法解决我的荨麻依赖问题。

我的问题

我在试图解决这些麻烦事依赖问题时做错了什么?

奖金问题

有解决这些ld链接器依赖关系的最佳实践吗?现在我的流量是这样的:

  1. 运行构建
  2. 注意“未定义引用”错误
  3. 通过搜索错误或查看引用的名称(例如,nettle_sha1_digest = nettle ),找出丢失了哪个包
  4. 安装那个软件包
  5. 重复

我想我想知道是否有一个神奇的子弹可以为我安装所有的依赖关系?:)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-11-16 06:51:32

从外观上看,您正在以错误的顺序链接依赖库(有关更多上下文,请参见Why does the order in which libraries are linked sometimes cause errors in GCC? )。

通过静态链接库,链接器试图按照指定库的顺序解析符号。如果依赖符号显示为未定义,则链接器将查看它是否在指定的后续库中定义。由于在构建调用中,-lnettle是在 -lgnutls之前指定的,所以gnutls库无法解析它所需要的符号。

这意味着(至少)您必须将对-lnettle的引用移到-lgnutls之后。不确定这将解决所有问题,因为我不熟悉您列出的所有链接依赖关系,但它至少应该解决运行go build的当前错误。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47318505

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档