2013-11-28 71 views
0

我有問題,作爲++嘗試我收到以下錯誤的對象文件鏈接的G:這是爲什麼,因爲例如情況克++未定義的引用,雖然所有的文件包括

11:29:13 **** Build of configuration Debug for project daytime **** 
make all 
'Building target: daytime' 
'Invoking: Cross G++ Linker' 
g++ -o "daytime" ./tcf/services/daytime.o ./tcf/main/main.o 
./tcf/services/daytime.o: In function `command_get_time_of_day': 
C:\Users\falkstef\runtime-EclipseApplication\daytime\Debug/../tcf/services/daytime.c:38: undefined reference to `json_read_string' 
C:\Users\falkstef\runtime-EclipseApplication\daytime\Debug/../tcf/services/daytime.c:40: undefined reference to `exception' 
C:\Users\falkstef\runtime-EclipseApplication\daytime\Debug/../tcf/services/daytime.c:43: undefined reference to `exception' 
C:\Users\falkstef\runtime-EclipseApplication\daytime\Debug/../tcf/services/daytime.c:52: undefined reference to `write_stringz' 
makefile:46: recipe for target 'daytime' failed 
C:\Users\falkstef\runtime-EclipseApplication\daytime\Debug/../tcf/services/daytime.c:54: undefined reference to `write_stringz' 
C:\Users\falkstef\runtime-EclipseApplication\daytime\Debug/../tcf/services/daytime.c:56: undefined reference to `write_errno' 
C:\Users\falkstef\runtime-EclipseApplication\daytime\Debug/../tcf/services/daytime.c:58: undefined reference to `json_write_string' 
./tcf/services/daytime.o: In function `ini_daytime_service': 
C:\Users\falkstef\runtime-EclipseApplication\daytime\Debug/../tcf/services/daytime.c:70: undefined reference to `add_command_handler' 
collect2.exe: error: ld returned 1 exit status 
make: *** [daytime] Error 1 

我不知道包括並找到#include <tcf/framework/json.h>

沒有的gcc編譯相應的*.c文件,出現這個連接錯誤? 這裏有什麼問題?

謝謝。

+0

您是否在您的環境(json)中構建/安裝該lib?你指定了鏈接庫嗎? –

回答

1

僅包含頭文件是不夠的;您還必須指定定義這些函數的庫。

要使鏈接器找到所有這些方法/類(json_read_string,write_stringz, exception),您需要引用該庫。如果例如它們包含在一個名爲libjson.so庫,你應該做的:

g++ -ljson -o "daytime" ./tcf/services/daytime.o ./tcf/main/main.o 

(或庫添加到項目選項,如果Eclipse管理您的make文件)。

或者,如果它的另一個.o文件將包括在彙編( - >或項目,如果Eclipse創建make文件)。

+0

這些不是共享庫。他們沒有編譯。只有.h和.c文件,如果包含它們,我希望它們由gcc編譯。 – displayname

+0

它們是否在您運行的命令(daytime.o/main.o)中指定的那兩個文件之一中?如果他們不在那裏,請將包含它們的.c文件包含在項目中,如上所述... – codeling

相關問題