2013-10-31 39 views
1

我試圖編譯它使用的hunspell庫用gcc這種純粹的C源代碼(4.6.3版本)編譯來源:鏈接問題在Ubuntu 10.10使用中的hunspell庫

#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; 
} 

隨着命令:

gcc -lhunspell-1.3 example.c 

但我有一些問題鏈接:

/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存在幷包含來自我的源的所有函數。
我在做什麼錯了,爲什麼我不能編譯這個源代碼?

回答

3

嘗試:

$ gcc example.c -lhunspell-1.3 

See the documentation-l選項:

這使得其中的命令寫這個選項的差異;鏈接器按照它們指定的順序搜索和處理庫和對象文件。因此,'foo.o -lz bar.o'在文件'foo.o'之後但在'bar.o'之前搜索庫'z'。如果'bar.o'引用'z'中的函數,則可能不會加載這些函數。

所以,你問GCC來第一搜索庫,然後編譯代碼。您需要以相反的方式執行此操作,您通常會在命令行上指定庫與最後一個進行鏈接。

也驗證庫文件在磁盤上的名字,經常有從名稱中刪除版本號的符號鏈接,所以也許你的命令應該僅僅是:

$ gcc example.c -lhunspell 

反對「當前鏈接「你的系統上有可用的庫版本。

+0

你是對的,謝謝! –