C 使用拼写库编译源代码时链接器问题

C 使用拼写库编译源代码时链接器问题,c,linker,linker-errors,hunspell,C,Linker,Linker Errors,Hunspell,我正在尝试编译这个纯C源代码,它在Ubuntu 10.10上使用了hunspell库和gcc(版本4.6.3): #include <stdlib.h> #include <stdio.h> #include <hunspell/hunspell.h> int main() { Hunhandle *spellObj = Hunspell_create("/home/artem/en_US.aff", "/home/artem/en_US.dic")

我正在尝试编译这个纯C源代码,它在Ubuntu 10.10上使用了hunspell库和gcc(版本4.6.3):

#include <stdlib.h>
#include <stdio.h>
#include <hunspell/hunspell.h>

int main() {
    Hunhandle *spellObj = Hunspell_create("/home/artem/en_US.aff", "/home/artem/en_US.dic");

    char str[60];
    scanf("%s", str);
    int result = Hunspell_spell(spellObj, str);

    if(result == 0)
        printf("Spelling error!\n");
    else
        printf("Correct Spelling!");

    Hunspell_destroy(spellObj);
    return 0;
}
但我有一些链接器问题:

/tmp/cce0QZnA.o: In function `main':
example.c:(.text+0x22): undefined reference to `Hunspell_create'
example.c:(.text+0x52): undefined reference to `Hunspell_spell'
example.c:(.text+0x85): undefined reference to `Hunspell_destroy'
collect2: ld returned 1 exit status
此外,我还检查了
/usr/include/hunspell/
文件夹,文件hunspell.h存在并包含我源代码中的所有函数。
我做错了什么,为什么我不能编译这个源代码?

试试:

$ gcc example.c -lhunspell-1.3
对于
-l
选项:

在命令中写入此选项的位置会有所不同;链接器按照指定的顺序搜索和处理库和对象文件。因此,
'foo.o-lz bar.o'
在文件'foo.o'之后但在'bar.o'之前搜索库'z'。如果'bar.o'指的是'z'中的函数,则可能不会加载这些函数

因此,您要求GCC首先搜索库,然后编译代码。您需要以另一种方式进行操作,通常在命令行上指定要链接的库

还要验证库文件的磁盘名称,通常会有符号链接从名称中删除版本号,因此您的命令可能只是:

$ gcc example.c -lhunspell
链接到系统上可用的“当前”库版本

$ gcc example.c -lhunspell