从过去几个小时我一直在浏览的其他问题中,我发现在编译此文件时链接未正确使用Json :: Value作为我函数中的参数buildTree。但是,我似乎无法自行解决这个问题,所以我现在正在寻求帮助。
在我的文件MovieClient.cpp的顶部,我已经包含以下内容:
#include <jsonrpccpp/client/connectors/httpclient.h>
#include <jsoncpp/json/value.h>
#include "moviestub.h"
using namespace jsonrpc;
using namespace std;
据我所知,并非所有这些都是相关的,但我想包括所有可能重要的人,因为我显然无法弄明白。
我也有前瞻声明:
void buildTree(Json::Value videoList);
该方法(注意:这是来自其他源材料,我还没有按照我的需要进行自定义。我之前尝试解决错误):
void buildTree(Json::Value videoList){
tree->clear();
cout << endl << "Adding tree nodes for video titles: ";
for(int i=0; i<videoList.size(); i++){
string title = videoList[i].asString();
std::stringstream stream;
stream << "Video"
<< "/" << title;
tree->add(stream.str().c_str());
}
cout << endl;
tree->root_label(appAuthor.c_str());
tree->redraw();
}
在main方法中调用(在前一个方法之后和类之外):
int main(int argc, char * argv[]) {
std::string nameStr = "Movie Library Catalog";
std::string host = (argc>0)?argv[0]:"127.0.0.1:8888";
MovieClient mc(nameStr,host);
HttpClient httpclient(host);
moviestub m(httpclient);
Json::Value videoList = m.getTitles();
buildTree(videoList);
return (Fl::run());
}
最后,这是构建文件的相关部分:
<target name="prepare">
<mkdir dir="${build}"/>
<mkdir dir="${dist}"/>
<mkdir dir="${obj}"/>
<property name="cxxflag" value="-std=c++14"/>
<property name="includepath" value="/usr/local/include"/>
<property name="client.lib.path" value="/usr/local/lib"/>
<property name="client.lib.list" value="jsoncpp,jsonrpccpp-client,jsonrpccpp-common,microhttpd,stdc++,fltk,X11,m,dl,pthread"/>
</target>
<target name="build.java.server"
depends="prepare"
description="Compile Java server sources">
<echo message="http server: java -cp classes:lib/jsonrpcserver.jar server.MovieLibraryHttpServer ${port.num}"/>
<javac srcdir="${src}/java/server"
includeantruntime="false"
destdir="${build}">
<classpath refid="compile.classpath"/>
</javac>
</target>
<target name="generate.client.stub" depends="prepare">
<exec dir="${basedir}" executable="jsonrpcstub">
<arg line="${json.file.name} --cpp-client=moviestub"/>
</exec>
<copy file="moviestub.h" tofile="${src}/cpp/client/moviestub.h"/>
<delete file="moviestub.h"/>
</target>
<target name="build.cpp.client" depends="generate.client.stub"
description="Compile C++ Client">
<cc outtype="executable" subsystem="console"
outfile="${dist}/movieBrowser"
objdir="${obj}">
<compiler name="g++"/>
<compilerarg value="${cxxflag}"/>
<includepath>
<pathelement path="${includepath}"/>
</includepath>
<libset dir="${client.lib.path}" libs="${client.lib.list}"/>
<fileset dir="${src}/cpp/client" includes="MovieClientGui.cpp,MovieClient.cpp"/>
</cc>
</target>
我得到的错误如下:
prepare:
generate.client.stub:
[copy] Copying 1 file to /home/kendra/Documents/SER321/Assign5/src/cpp/client
[delete] Deleting: /home/kendra/Documents/SER321/Assign5/moviestub.h
build.cpp.client:
[cc] Starting dependency analysis for 1 files.
[cc] 1 files are up to date.
[cc] 0 files to be recompiled from dependency analysis.
[cc] 1 total files to be compiled.
[cc] Starting link
[cc] ../obj/MovieClient.o: In function `main':
[cc] MovieClient.cpp:(.text+0x22f): undefined reference to `buildTree(Json::Value)'
[cc] collect2: error: ld returned 1 exit status
那么,这里的问题是Json :: Value没有正确定义吗?我的build.xml中的列表中是否缺少文件?或者我不允许使用Json :: Value作为参数类型?
或者它完全是另一回事吗?