2012-09-20 21 views
0

我在編譯Example of a C program embedding ECL with callbacks to C functions.github。我已經安裝了ECL (Embeddable Common Lisp)克隆ECL回購與git clone git://git.code.sf.net/p/ecls/ecl ecl然後$ make# make install,並且安裝似乎沒問題,至少ECL Developers' Guide: 2.6 Compiler examples編譯好。/usr/bin/ld:error:找不到-lecl

當試圖編譯ecldemo.cgcc ecldemo.c -lecl我收到以下錯誤:

/usr/bin/ld: error: cannot find -lecl 
/tmp/ccRk8Q48.o:ecldemo.c:function foo: error: undefined reference to 'ecl_make_integer' 
/tmp/ccRk8Q48.o:ecldemo.c:function bar: error: undefined reference to 'ecl_make_integer' 
/tmp/ccRk8Q48.o:ecldemo.c:function ecl_call: error: undefined reference to 'ecl_make_simple_base_string' 
/tmp/ccRk8Q48.o:ecldemo.c:function ecl_call: error: undefined reference to 'si_string_to_object' 
/tmp/ccRk8Q48.o:ecldemo.c:function ecl_call: error: undefined reference to 'si_safe_eval' 
/tmp/ccRk8Q48.o:ecldemo.c:function init: error: undefined reference to 'cl_boot' 
/tmp/ccRk8Q48.o:ecldemo.c:function init: error: undefined reference to 'cl_shutdown' 
/tmp/ccRk8Q48.o:ecldemo.c:function init: error: undefined reference to 'ecl_make_simple_base_string' 
/tmp/ccRk8Q48.o:ecldemo.c:function init: error: undefined reference to 'si_string_to_object' 
/tmp/ccRk8Q48.o:ecldemo.c:function init: error: undefined reference to 'ecl_def_c_function' 
/tmp/ccRk8Q48.o:ecldemo.c:function init: error: undefined reference to 'ecl_make_simple_base_string' 
/tmp/ccRk8Q48.o:ecldemo.c:function init: error: undefined reference to 'si_string_to_object' 
/tmp/ccRk8Q48.o:ecldemo.c:function init: error: undefined reference to 'ecl_def_c_function' 
/tmp/ccRk8Q48.o:ecldemo.c:function main: error: undefined reference to 'ecl_make_simple_base_string' 
/tmp/ccRk8Q48.o:ecldemo.c:function main: error: undefined reference to 'si_string_to_object' 
/tmp/ccRk8Q48.o:ecldemo.c:function main: error: undefined reference to 'si_safe_eval' 
/tmp/ccRk8Q48.o:ecldemo.c:function main: error: undefined reference to 'cl_print' 
/tmp/ccRk8Q48.o:ecldemo.c:function main: error: undefined reference to 'cl_equal' 
collect2: error: ld returned 1 exit status 

我不知道這個錯誤行:

/usr/bin/ld: error: cannot find -lecl 

在我看來,那gcc某種程度上解釋-lecl作爲源文件,而不是作爲選項-l library(搜索名爲library的庫)。在-leclgcc ecldemo.c -l ecl)之間留出空格不起作用,輸出結果相同(cannot find -lecl)。

由於ecl.h位於/usr/local/include/ecl/ecldemo.c它包含#include "ecl/ecl.h",我嘗試添加一個圖書館目錄與-L選項:

gcc -L /usr/local/include/ecl ecldemo.c -l ecl

...但無濟於事,同樣的錯誤usr/bin/ld: error: cannot find -lecl堅持。

任何想法可能會導致此錯誤,怎麼可能解決這個問題?

+0

-lecl告訴GCC檢索爲一個叫libecl的圖書館。 Ld告訴你它找不到這樣的庫。你有沒有在你的圖書館路徑?如果不是這樣的路徑必須用-L指定。另請注意,「ecl.h」是庫的頭文件。擁有這樣的文件並不意味着你編譯了這個庫 – Jack

+0

「libecl.a」或「libecl.so」文件在哪裏?這是您需要爲'-L'選項設置的目錄。 –

回答

6

您的-L選項是錯誤的。您需要告訴它在哪裏可以找到,而不是在哪裏可以找到頭文件。圖書館最有可能被稱爲libecl.solibecl.a或類似的東西。

+0

+1非常感謝,這解決了我的問題。正確的'gcc'命令是'gcc ecldemo.c -L/usr/local/lib -lecl'。 – nrz

1

不要指定-lecl-L...直接使用ecl-config代替:

gcc `ecl-config --cflags` ecldemo.c -o ecldemo `ecl-config --libs`