TL;博士
我正在尝试构建一个使用这个依赖项的go项目:https://github.com/mqu/openldap,它反过来对外链接lldap和llber库,后者又使用lgnutls,它使用lnettle,这就是我陷入困境的地方。
go build生成一长串未定义的引用,生成失败。这是一个样本:
/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命令:
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"'我已经尝试通过安装libnettle4、nettle-dev、libghc-nettle-dev、nettle-bin来解决这个问题。我已经确保将-lnettle包含在in标志中。不走运。
更多上下文
openldap库链接代码中的ldap和lber库:
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链接器依赖关系的最佳实践吗?现在我的流量是这样的:
nettle_sha1_digest = nettle ),找出丢失了哪个包我想我想知道是否有一个神奇的子弹可以为我安装所有的依赖关系?:)
发布于 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的当前错误。
https://stackoverflow.com/questions/47318505
复制相似问题