2015-06-09 62 views
0

我是C語言的新手,每當我用命令cc prompt.c編譯我的C代碼時都會收到此錯誤。我得到這個錯誤:修改錯誤

Undefined symbols for architecture x86_64:

"_add_history", referenced from:

_main in prompt-66f61f.o 

"_readline", referenced from:

_main in prompt-66f61f.o 

ld: symbol(s) not found for architecture x86_64

clang: error: linker command failed with exit code 1 (use -v to see invocation)

這裏是我的代碼:

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

#include <editline/readline.h> 


int main(int argc, char** argv) { 

    /* Print Version and Exit Information */ 
    puts("Lispy Version 0.0.0.0.1"); 
    puts("Press Ctrl+c to Exit\n"); 

    /* In a never ending loop */ 
    while (1) { 

    /* Output our prompt and get input */ 
    char* input = readline("lispy> "); 

    /* Add input to history */ 
    add_history(input); 

    /* Echo input back to user */  
    printf("No you're a %s\n", input); 

    /* Free retrieved input */ 
    free(input); 

    } 

    return 0; 
} 

我寫在MacBook Air上這個程序運行OSX 10.10.3,有沒有什麼幫助。

我剛剛開始學習C語言,所以不要評論我這個問題是否真的很簡單,當我搜索它時沒有結果。

任何幫助將不勝感激。謝謝!

+0

你在編制呢? – cehnehdeh

回答

1

爲了使鏈接器找到readlineadd_history函數的定義,您需要將程序鏈接到editline庫。

你可以在你的編譯命令與-l標誌,指定庫這樣做:

cc prompt.c -ledit 
+0

我嘗試了你所說的並得到了同樣的錯誤。 – TheBestCoder

+0

@TheBestCoder你有沒有按照['editline' website](http://thrysoee.dk/editline/)上的指示?看來你還需要包含'-lcurses'。 – emlai

+0

@TheBestCoder另外,如果你有'pkg-config',你可以簡單地使用'''pkg-config --libs --cflags libedit \''而不是'-l'標誌,它會擴展到合適的標誌。 – emlai