Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ g++;未定义的引用,尽管包含所有文件_C++_Eclipse_Gcc_G++ - Fatal编程技术网

C++ g++;未定义的引用,尽管包含所有文件

C++ g++;未定义的引用,尽管包含所有文件,c++,eclipse,gcc,g++,C++,Eclipse,Gcc,G++,我的问题是,当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/daytim

我的问题是,当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

gcc是否编译了相应的
*.c
文件,导致出现此链接器错误? 这里有什么问题


谢谢。

仅包含头文件是不够的;您还必须指定定义这些函数的库

要使链接器找到所有这些方法/类(
json\u read\u string
write\u stringz
exception
),您需要引用库。例如,如果它们包含在名为libjson.so的库中,则应执行以下操作:

g++ -ljson -o "daytime"  ./tcf/services/daytime.o  ./tcf/main/main.o
(如果eclipse正在管理make文件,也可以将库添加到项目选项中)


或者,如果它是另一个.o文件,请将其包含在编译(->或项目中,如果eclipse正在创建make文件)。

这些不是共享库。它们没有被编译。只有.h和.c文件,如果包含它们,我希望由gcc编译。它们是否在正在运行的命令(day.o/main.o)中指定的两个文件之一中?如果它们不在其中,请将包含它们的.c文件包含在项目中,如上所述……您是否在您的环境(json)中构建/安装了该库??是否指定了用于链接的库?