go - cgo - 在 GO 中链接动态库时出现“未定义引用”错误
问题描述
我有一个 C++ 共享库/opt/xx/lib64
。标头在 C 中。在我的 go 代码中,我使用 CPPFLAGS/CFLAGS 和 LDFLAGS 包含正确的标头和链接器选项。仍然在构建过程中,我收到“未定义的引用”错误。
import (
//#cgo LDFLAGS: -L/opt/xxx/lib64/ -lsessionmgmt
//#cgo CPPFLAGS: -I/opt/xxx/include/
//#include <stdlib.h>
//#include <sessionMgmt/sessionMgmt.h>
"C"
"unsafe"
)
/tmp/go-build609413262/b163/_x002.o: In function `_cgo_e38947506e9d_Cfunc_um_get_lastlogin_info':
/tmp/go-build/cgo-gcc-prolog:52: undefined reference to `um_get_lastlogin_info'
collect2: error: ld returned 1 exit status
make[3]: *** [Makefile:48: vet] Error 2
库存在于正确的路径中,并且确实包含所需的方法。不知道为什么会出现这个错误。
$ grep um_get_lastlogin_info /opt/xxx/lib64/libsessionmgmt.so
Binary file /opt/xxx/lib64/libsessionmgmt.so matches
还尝试使用pkg-config
with cgo。仍然出现相同的链接错误。
解决方案
推荐阅读
- java - Java 数据格式并非适用于所有场景
- powershell - 使用 PowerShell 获取最新的 Go 语言版本
- reactjs - 如何删除选项卡导航器上的前一个屏幕 - React Navigation v5
- inheritance - 是否可以在构造函数中使用 this.fieldname 来初始化基类中的字段?
- python - 属性错误 Nonetype 没有属性 getItem
- python - 有没有办法模拟 Windows alt-tabbing?
- ios - 当我使用 .ascii 编码解码 HTML 页面时出现奇怪的字符串
- javascript - Javascript - 如果数组为空,则隐藏/显示元素
- postgresql - 如果模式已在数据库中手动定义,则在所有实体中与 Hibernate 进行关联映射的目的
- python - 意外的关键字参数'min_col'错误复制工作表openpyxl