我正在尝试编译依赖于 gtkspell 的东西,它
取决于附魔,在 MinGW 下。我收到类似的错误
gtkspell/gtkspell.c:757:对“_imp__enchant_broker_init”的 undefined reference
我怀疑这是因为我正在尝试链接
当我应该链接到 {static,dynamic} 库时
另一个,或者因为 imp 和之前只有一个下划线
应该有两个;我明白了
$ objdump -t /d/opt/enchant-1.6.0/lib/libenchant.a | grep enchant_broker_init
[ 85](sec 1)(fl 0x00)(ty 20)(scl 2) (nx 0) 0x00002ac0 _enchant_broker_init
和
$ objdump -t /d/opt/enchant-1.6.0/lib/libenchant.dll.a | grep enchant_broker_init
[ 6](sec 1)(fl 0x00)(ty 0)(scl 2) (nx 0) 0x00000000 _enchant_broker_init
[ 7](sec 3)(fl 0x00)(ty 0)(scl 2) (nx 0) 0x00000000 __imp__enchant_broker_init
互联网 (http://lists.freedesktop.org/archives/gstreamer-devel/2007-January/013975.html) 建议 imp mangling 来自
_declspec(dll{import,export})
虽然附魔似乎使用
__declspec(dll{import,export})
,并注释掉 enchant.h 中的相关行,生成 gtkspell.c
请求 enchant_broker_init
而不是 _imp__enchant_broker_init
,但是
不会更改出现在 libenchant 中的符号。有没有办法
使 gcc 不破坏名称,或者有人对什么有想法
可能出了问题/如何解决?
这是一个在我的系统上重现问题的最小示例:
如果我有一个包含内容的文件 enchanttest1.c
#include <stdio.h>
#include <enchant.h>
int main()
{
#ifdef ENCHANT_MODULE_EXPORT
printf("\nEnchant found\n");
#else
printf("\nEnchant not found\n");
#endif
return 0;
}
和一个包含内容的文件 enchanttest2.c
#include <stdio.h>
#include <enchant.h>
int main()
{
EnchantBroker *b = enchant_broker_init();
#ifdef ENCHANT_MODULE_EXPORT
printf("\nEnchant found\n");
#else
printf("\nEnchant not found\n");
#endif
return 0;
}
然后
gcc enchanttest1.c `pkg-config --cflags enchant` && ./a.exe
给出 Enchant found
但是
gcc enchanttest2.c `pkg-config --cflags enchant` && ./a.exe
给予
C:\Users\JASONG~1\AppData\Local\Temp\ccyDLptc.o:testenchant.c:(.text+0xf): undefined reference to `_imp__enchant_broker_init'
collect2: ld returned 1 exit status
最佳答案
修复我的最小示例的方法是在 --cflags
之后添加 --libs
; gcc 找不到要链接的库。
通过传递 LDFLAGS="$(pkg-config - -cflags --libs gtkspell-2.0 enchant)"CFLAGS="$(pkg-config --cflags --libs gtkspell-2.0 enchant)"
配置脚本;问题似乎是 gcc 的参数以错误的顺序传递,并且在尝试链接 gtkspell 时找不到附魔。
关于c - 如何修复对 _imp__* 的 undefined reference ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10059200/