1

From other questions that I've been looking through for the past couple of hours, I gather that the link isn't being made correctly when I compile this file I'm using Json::Value as a parameter in my function buildTree. However, I cannot seem to correct this on my own so I'm reaching out for help now.

At the top of my file MovieClient.cpp, I've included the following:

#include <jsonrpccpp/client/connectors/httpclient.h>
#include <jsoncpp/json/value.h>
#include "moviestub.h"

using namespace jsonrpc;
using namespace std;

Not all of these are relevant, as far as I know, but I wanted to include all of those who may matter since I obviously can't figure it out.

I also have the forward declaration:

void buildTree(Json::Value videoList);

The method (note: this is from other source material and I haven't finished customizing it to what I need. I was trying to resolve the error before doing so):

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();
}

It's called in the main method (after the previous method and outside the class):

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());
}

Finally, here's the relevant portion of the build file:

<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>

The error I'm getting is the following:

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

So, is the issue here that Json::Value is not correctly defined? Is a file missing in my list in my build.xml vile? Or am I just not allowed to use Json::Value as a parameter type?

Or is it something else completely?

Kendra
  • 125
  • 2
  • 12
  • 2
    Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – vasek Sep 25 '17 at 10:02
  • 2
    When you say "method" you seem to mean "function". Usually people translate "method" into "member function" in C++ which isn't what you mean. – nwp Sep 25 '17 at 10:08
  • Oh jeez. I forgot to add the error I'm getting. Adding that in a second. – Kendra Sep 25 '17 at 10:12
  • @vasek I read through that but I still couldn't figure out how to apply it specifically to my situation. – Kendra Sep 25 '17 at 10:23
  • That was a typo just in this post. I've corrected it now. – Kendra Sep 25 '17 at 10:27
  • Make sure the file containing the definition for `buildTree` is being compiled and linked. If that doesn't help try to make a [mcve] to give people a chance to reproduce the problem. – nwp Sep 25 '17 at 11:07

0 Answers0