--- YOUR OUTPUT ----
make -k all
g++ myXmlRpcServerMethods.cpp -o myXmlRpcServerMethods
(...)
g++ myXmlRpcServer.cpp -o myXmlRpcServer
--- END OF YOUR OUTPUT ----
That means, you are not linking any lib. The g++ output should be something like this:
g++ myXmlRpcServerMethods.cpp -o myXmlRpcServerMethods -lXmlRpc
The last link-command (-lXmlRpc) I wrote, means that you use the libXmlRpc.so (or libXmlRpc.a) file. This is the XmlRpc++ library and it has to be added, it is not a standard lib.
If you install it in a folder that is *not* in the default libs folder, you also need the -L command. For example, let's say you compile the XmlRpc++ library and save the libXmlRpc.so file in /home/myname/XmlRpc/lib; then, your command line should look like:
g++ myXmlRpcServerMethods.cpp -o myXmlRpcServerMethods -L/home/myname/XmlRpc/lib -lXmlRpc
Normally, in the Makefile, you have a LIB variable; add the information there.
Regards,
José
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I've just started studying xmprpc++ and collected some examples from net to try out. What I have are the following:
<Code>
File 1:
#ifndef OPERATIONS_H_
#define OPERATIONS_H_
#include <iostream>
class Operations {
public:
int add();
Operations(){
op1 = 0;
op2 = 0;
};
Operations(int i, int j){
op1 = i;
op2 = j;
};
private:
int op1;//Operand 1
int op2;//Operand 2
};
#endif /*OPERATIONS_H_*/
File 2:
#include "Operations.h"
using namespace std;
int Operations::add()
{
std::cout << "Sum of "<<op1<<" + "<<op2<<" = "<<op1+op2<<std::endl;
return(op1 + op2);
}
int main () {
std::cout<<"Hello World!"<<std::endl;
Operations* t = new Operations(2,3);
t->add();
return 0;
}
File 3:
#ifndef MYXMLRPCSERVERMETHODS_H_
#define MYXMLRPCSERVERMETHODS_H_
#include <XmlRpcServerMethod.h>
#include <XmlRpcServer.h>
#include <XmlRpcValue.h>
using namespace XmlRpc;
class myXmlRpcServerMethod : public XmlRpcServerMethod
{
public:
myXmlRpcServerMethod
(const char* name, XmlRpcServer* server):XmlRpcServerMethod(name, server) {}
virtual void execute(XmlRpcValue& params, XmlRpcValue& result) {assert(0);}
};
class Add:public myXmlRpcServerMethod
{
public:
Add(XmlRpcServer* s);
virtual void execute(XmlRpcValue& params, XmlRpcValue& result);
};
#endif /*MYXMLRPCSERVERMETHODS_H_*/
File 4:
#include <iostream>
#include "myXmlRpcServer.h"
#include "operations.h"
using namespace std;
using namespace XmlRpc;
Add::Add(XmlRpcServer* s) : myXmlRpcServerMethod("Add", s) {};
void Add::execute(XmlRpcValue & params, XmlRpcValue& result)
{
Operations a(10,12);
try
{
cout << "Inside Add::execute method\n";
result = a.add();
}
catch(std::exception & stde)
{
throw XmlRpcException(stde.what());
}
}
int main()
{
}
File 5:
#ifndef MYXMLRPCSERVER_H_
#define MYXMLRPCSERVER_H_
#include <iostream>
#include "myXmlRpcServerMethods.h"
#include <XmlRpc.h>
class myXmlRpcServer {
public:
myXmlRpcServer();
void run();
private:
void pm_registerMethods();
XmlRpc::XmlRpcServer pm_xmlRpcServer;
std::list< myXmlRpcServerMethod* > pm_serverMethods;
};
#endif /*MYXMLRPCSERVER_H_*/
File 6:
#include "myXmlRpcServer.h"
using namespace XmlRpc;
using namespace std;
myXmlRpcServer::myXmlRpcServer()
{
//call register methods
pm_registerMethods();
//set port bind and listen
int port = 8085;
pm_xmlRpcServer.bindAndListen(port);
std::cout<<"XmlRpcSever running in port "<<port<<std::endl;
}
void
myXmlRpcServer::pm_registerMethods()
{
Add* a=new Add(&pm_xmlRpcServer);
myXmlRpcServerMethod *p=a;
pm_serverMethods.push_back(p);
}
void
myXmlRpcServer::run()
{
pm_xmlRpcServer.work(-1);
}
int main()
{
}
File 7:
#include <iostream>
#include "myXmlRpcServer.h"
int main(int argc, char* argv[])
{
myXmlRpcServer GeeBoomBaa;
std::cout<<"About to run the server\n";
GeeBoomBaa.run();
return 0;
}
My Make File:
makefile:
CC= g++
CFLAGS= -g -O2 -D_WIN32 -DWIN32
LDFLAGS=
LIBS= -llibXmlRpc
#-Wl,-u,_WinMain@16 -lV -lcomctl32 -mwindows
OBJECTS= Operations myXmlRpcServerMethods myXmlRpcServer myServerDriver
all: $(OBJECTS)
clean:
-rm -f *.o
%.exe : %.o
$(CC) $(CFLAGS) $(LIBS) $@.o -o $(LDFLAGS) $@.exe
%.o : %.cpp
$(CC) $(CFLAGS) -c $<
</Code>
I'm using Cygwin g++ and building apps from Eclipse.
I'm getting the following errors:
make -k all
g++ myXmlRpcServerMethods.cpp -o myXmlRpcServerMethods
/cygdrive/c/DOCUME~1/PRANAB~1/LOCALS~1/Temp/ccYZYzRj.o:myXmlRpcServerMethods.cpp:(.text+0x1cd): undefined reference to `Operations::add()'
/cygdrive/c/DOCUME~1/PRANAB~1/LOCALS~1/Temp/ccYZYzRj.o:myXmlRpcServerMethods.cpp:(.text$_ZN20myXmlRpcServerMethodC2EPKcPN6XmlRpc12XmlRpcServerE[myXmlRpcServerMethod::myXmlRpcServerMethod(char const*, XmlRpc::XmlRpcServer*)]+0x7c): undefined reference to `XmlRpc::XmlRpcServerMethod::XmlRpcServerMethod(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, XmlRpc::XmlRpcServer*)'
/cygdrive/c/DOCUME~1/PRANAB~1/LOCALS~1/Temp/ccYZYzRj.o:myXmlRpcServerMethods.cpp:(.text$_ZN6XmlRpc11XmlRpcValueaSERKi[XmlRpc::XmlRpcValue::operator=(int const&)]+0x5e): undefined reference to `XmlRpc::XmlRpcValue::operator=(XmlRpc::XmlRpcValue const&)'
/cygdrive/c/DOCUME~1/PRANAB~1/LOCALS~1/Temp/ccYZYzRj.o:myXmlRpcServerMethods.cpp:(.text$_ZN6XmlRpc11XmlRpcValueD1Ev[XmlRpc::XmlRpcValue::~XmlRpcValue()]+0xd): undefined reference to `XmlRpc::XmlRpcValue::invalidate()'
/cygdrive/c/DOCUME~1/PRANAB~1/LOCALS~1/Temp/ccYZYzRj.o:myXmlRpcServerMethods.cpp:(.text$_ZN20myXmlRpcServerMethodD0Ev[myXmlRpcServerMethod::~myXmlRpcServerMethod()]+0x16): undefined reference to `XmlRpc::XmlRpcServerMethod::~XmlRpcServerMethod()'
/cygdrive/c/DOCUME~1/PRANAB~1/LOCALS~1/Temp/ccYZYzRj.o:myXmlRpcServerMethods.cpp:(.text$_ZN20myXmlRpcServerMethodD1Ev[myXmlRpcServerMethod::~myXmlRpcServerMethod()]+0x16): undefined reference to `XmlRpc::XmlRpcServerMethod::~XmlRpcServerMethod()'
/cygdrive/c/DOCUME~1/PRANAB~1/LOCALS~1/Temp/ccYZYzRj.o:myXmlRpcServerMethods.cpp:(.text$_ZN20myXmlRpcServerMethodD2Ev[myXmlRpcServerMethod::~myXmlRpcServerMethod()]+0x16): undefined reference to `XmlRpc::XmlRpcServerMethod::~XmlRpcServerMethod()'
collect2: ld returned 1 exit status
make: *** [myXmlRpcServerMethods] Error 1
g++ myXmlRpcServer.cpp -o myXmlRpcServer
/cygdrive/c/DOCUME~1/PRANAB~1/LOCALS~1/Temp/cc3OojYK.o:myXmlRpcServer.cpp:(.text+0x143): undefined reference to `XmlRpc::XmlRpcServer::XmlRpcServer()'
/cygdrive/c/DOCUME~1/PRANAB~1/LOCALS~1/Temp/cc3OojYK.o:myXmlRpcServer.cpp:(.text+0x1c6): undefined reference to `XmlRpc::XmlRpcServer::bindAndListen(int, int)'
/cygdrive/c/DOCUME~1/PRANAB~1/LOCALS~1/Temp/cc3OojYK.o:myXmlRpcServer.cpp:(.text+0x24b): undefined reference to `XmlRpc::XmlRpcServer::~XmlRpcServer()'
/cygdrive/c/DOCUME~1/PRANAB~1/LOCALS~1/Temp/cc3OojYK.o:myXmlRpcServer.cpp:(.text+0x2bd): undefined reference to `XmlRpc::XmlRpcServer::XmlRpcServer()'
/cygdrive/c/DOCUME~1/PRANAB~1/LOCALS~1/Temp/cc3OojYK.o:myXmlRpcServer.cpp:(.text+0x340): undefined reference to `XmlRpc::XmlRpcServer::bindAndListen(int, int)'
/cygdrive/c/DOCUME~1/PRANAB~1/LOCALS~1/Temp/cc3OojYK.o:myXmlRpcServer.cpp:(.text+0x3c5): undefined reference to `XmlRpc::XmlRpcServer::~XmlRpcServer()'
/cygdrive/c/DOCUME~1/PRANAB~1/LOCALS~1/Temp/cc3OojYK.o:myXmlRpcServer.cpp:(.text+0x454): undefined reference to `Add::Add(XmlRpc::XmlRpcServer*)'
/cygdrive/c/DOCUME~1/PRANAB~1/LOCALS~1/Temp/cc3OojYK.o:myXmlRpcServer.cpp:(.text+0x4df): undefined reference to `XmlRpc::XmlRpcServer::work(double)'
collect2: ld returned 1 exit status
make: *** [myXmlRpcServer] Error 1
make: Target `all' not remade because of errors.
Any help/pointers to resolve this would be greatly appreciated.
-Thanks,
prdas.
Hi,
I noticed the following:
--- YOUR OUTPUT ----
make -k all
g++ myXmlRpcServerMethods.cpp -o myXmlRpcServerMethods
(...)
g++ myXmlRpcServer.cpp -o myXmlRpcServer
--- END OF YOUR OUTPUT ----
That means, you are not linking any lib. The g++ output should be something like this:
g++ myXmlRpcServerMethods.cpp -o myXmlRpcServerMethods -lXmlRpc
The last link-command (-lXmlRpc) I wrote, means that you use the libXmlRpc.so (or libXmlRpc.a) file. This is the XmlRpc++ library and it has to be added, it is not a standard lib.
If you install it in a folder that is *not* in the default libs folder, you also need the -L command. For example, let's say you compile the XmlRpc++ library and save the libXmlRpc.so file in /home/myname/XmlRpc/lib; then, your command line should look like:
g++ myXmlRpcServerMethods.cpp -o myXmlRpcServerMethods -L/home/myname/XmlRpc/lib -lXmlRpc
Normally, in the Makefile, you have a LIB variable; add the information there.
Regards,
José