2013-11-28 33 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

相关问题