0

I'm writing a program that takes magnet links and then uses RCP to call a remote client and open the magnet link in Deluge. I'm using xmlrpcc4win as my RPC lib. I'v spent possibly an hour on a half on it so far, most of that time Googling this error with little or no luck.

the code i have is as follows:

// ConsoleApplication6.cpp : Defines the entry point for the console application.
//
//This program is designed to open magnet links on a remote server using RPC calls.
#include "stdafx.h"
#include "timxmlrpc.h"
#include <iostream>
#include <string>
#include <fstream>

//some basic defines...
#define BASIC_OPPERATION 2
#define SUCCESS 0
#define FAILURE -1

//define funftion prototypes
int callRpc(std::string);
int checkUrl(std::string);


int main(int argc, char* argv[])
{
    //convert char* argv[] to string for error handling.
    std::string sPassedMagnet = argv[1];
    int status;

    //chect to see if program is being opened with the correct number of params
    if(BASIC_OPPERATION == argc)
    {
        //check passed link value
        checkUrl(sPassedMagnet);

        //start RCP call
        status = callRpc(sPassedMagnet);

        //handle errors
        if(SUCCESS != status)
        {
            std::cout << "Call not successfull" << std::endl;
            return FAILURE;
        }
        //print out a success message
        std::cout << "Call made was successfull\n" << std::endl;
        std::cout << "Hit Enter..." << std::endl;
        std::cin.get();
    }

    return SUCCESS;
}


int checkUrl(std::string sPassedMagnet){

        //nice simple bit of code to check if the link passed in is indeed
        //a magnet link, or just some random text that is of no use.


        //define local variables
        int status;
        std::string scheckMag = ("magnet:");

        //check to see if string passed in contains 'magnet:'
        if (std::string::npos != sPassedMagnet.find(scheckMag))
        {
            std::cout << "found magnet!\n\n" << std::endl;
            std::cout << "Magnet link: " << sPassedMagnet << "\n" << std::endl;
            status = SUCCESS;
        }
        //handle errors if the string does not contain :magnet
        else
        {
            std::cout << "That's not a magnet link...\n" << std::endl;
            std::cout << "Press any key...\n" << std::endl;
            std::cin.get();
            status = FAILURE;
        }

        return status;
}

int callRpc(std::string sPassedMagnet){

    //set client to connect to
    //maybe add a scan in from a config file?
    XmlRpcClient Connection("localhost:8080/RCP2");
    Connection.setIgnoreCertificateAuthority();

    //  Call:  add_torrent_magnet(uri, options):
    XmlRpcValue args, result;
    args[0] = sPassedMagnet;
    args[1] = 1;


    // Replace this function name with your own:
    if (! Connection.execute("add_torrent_magnet", args, result)) 
    {
        std::cout << Connection.getError();
    }
    //else if (result.getType() == XmlRpcValue::TypeString)
    //{
    //  std::cout << std::string(result);
    //}
    else
    {
        std::cout << "Success\n";
    }
    return SUCCESS;
}

So far the output when i build the code is as follows:

1>------ Build started: Project: ConsoleApplication6, Configuration: Debug Win32 ------
1>ConsoleApplication6.obj : error LNK2019: unresolved external symbol "public: class XmlRpcValue & __thiscall XmlRpcValue::operator=(class XmlRpcValue const &)" (??4XmlRpcValue@@QAEAAV0@ABV0@@Z) referenced in function "public: class XmlRpcValue & __thiscall XmlRpcValue::operator=(int const &)" (??4XmlRpcValue@@QAEAAV0@ABH@Z)
1>ConsoleApplication6.obj : error LNK2019: unresolved external symbol "protected: void __thiscall XmlRpcValue::invalidate(void)" (?invalidate@XmlRpcValue@@IAEXXZ) referenced in function "public: __thiscall XmlRpcValue::~XmlRpcValue(void)" (??1XmlRpcValue@@QAE@XZ)
1>ConsoleApplication6.obj : error LNK2019: unresolved external symbol "protected: void __thiscall XmlRpcValue::assertArray(int)" (?assertArray@XmlRpcValue@@IAEXH@Z) referenced in function "public: class XmlRpcValue & __thiscall XmlRpcValue::operator[](int)" (??AXmlRpcValue@@QAEAAV0@H@Z)
1>ConsoleApplication6.obj : error LNK2019: unresolved external symbol "public: __thiscall XmlRpcClient::XmlRpcClient(char const *)" (??0XmlRpcClient@@QAE@PBD@Z) referenced in function "int __cdecl callRpc(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?callRpc@@YAHV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
1>ConsoleApplication6.obj : error LNK2019: unresolved external symbol "public: bool __thiscall XmlRpcClient::execute(char const *,class XmlRpcValue const &,class XmlRpcValue &)" (?execute@XmlRpcClient@@QAE_NPBDABVXmlRpcValue@@AAV2@@Z) referenced in function "int __cdecl callRpc(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?callRpc@@YAHV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
1>ConsoleApplication6.obj : error LNK2019: unresolved external symbol "public: void __thiscall XmlRpcClient::setIgnoreCertificateAuthority(bool)" (?setIgnoreCertificateAuthority@XmlRpcClient@@QAEX_N@Z) referenced in function "int __cdecl callRpc(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?callRpc@@YAHV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
1>ConsoleApplication6.obj : error LNK2019: unresolved external symbol "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall XmlRpcClient::getError(void)" (?getError@XmlRpcClient@@QAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) referenced in function "int __cdecl callRpc(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?callRpc@@YAHV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
1>ConsoleApplication6.obj : error LNK2019: unresolved external symbol "public: void __thiscall XmlRpcClient::close(void)" (?close@XmlRpcClient@@QAEXXZ) referenced in function "public: __thiscall XmlRpcClient::~XmlRpcClient(void)" (??1XmlRpcClient@@QAE@XZ)
1>C:\Users\Joe\Documents\Visual Studio 2012\Projects\ConsoleApplication6\Debug\ConsoleApplication6.exe : fatal error LNK1120: 8 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Ok, now i have included timxmlrpc.cpp and linked wininet.lib to my project. I now get the following...

1>------ Build started: Project: ConsoleApplication6, Configuration: Debug Win32 ------
1>  stdafx.cpp
1>  ConsoleApplication6.cpp
1>c:\users\joe\documents\visual studio 2012\projects\consoleapplication6\consoleapplication6\timxmlrpc.h(60): error C2011: 'XmlRpcException' : 'class' type redefinition
1>          c:\users\joe\documents\visual studio 2012\projects\consoleapplication6\consoleapplication6\timxmlrpc.h(60) : see declaration of 'XmlRpcException'
1>c:\users\joe\documents\visual studio 2012\projects\consoleapplication6\consoleapplication6\timxmlrpc.h(75): error C2011: 'XmlRpcValue' : 'class' type redefinition
1>          c:\users\joe\documents\visual studio 2012\projects\consoleapplication6\consoleapplication6\timxmlrpc.h(75) : see declaration of 'XmlRpcValue'
1>c:\users\joe\documents\visual studio 2012\projects\consoleapplication6\consoleapplication6\timxmlrpc.h(297): error C2011: 'XmlRpcClient' : 'class' type redefinition
1>          c:\users\joe\documents\visual studio 2012\projects\consoleapplication6\consoleapplication6\timxmlrpc.h(297) : see declaration of 'XmlRpcClient'
1>c:\users\joe\documents\visual studio 2012\projects\consoleapplication6\consoleapplication6\timxmlrpc.cpp(62): error C2027: use of undefined type 'XmlRpcValue'
1>          c:\users\joe\documents\visual studio 2012\projects\consoleapplication6\consoleapplication6\timxmlrpc.h(75) : see declaration of 'XmlRpcValue'
1>c:\users\joe\documents\visual studio 2012\projects\consoleapplication6\consoleapplication6\timxmlrpc.cpp(108): error C2027: use of undefined type 'XmlRpcValue'
1>          c:\users\joe\documents\visual studio 2012\projects\consoleapplication6\consoleapplication6\timxmlrpc.h(75) : see declaration of 'XmlRpcValue'
1>c:\users\joe\documents\visual studio 2012\projects\consoleapplication6\consoleapplication6\timxmlrpc.cpp(110): error C2065: '_allocated' : undeclared identifier
1>c:\users\joe\documents\visual studio 2012\projects\consoleapplication6\consoleapplication6\timxmlrpc.cpp(121): error C2065: 'A' : undeclared identifier
1>c:\users\joe\documents\visual studio 2012\projects\consoleapplication6\consoleapplication6\timxmlrpc.cpp(122): error C2065: 'A' : undeclared identifier
1>c:\users\joe\documents\visual studio 2012\projects\consoleapplication6\consoleapplication6\timxmlrpc.cpp(122): error C2065: '_allocated' : undeclared identifier
1>c:\users\joe\documents\visual studio 2012\projects\consoleapplication6\consoleapplication6\timxmlrpc.cpp(123): error C2065: '_allocated' : undeclared identifier
1>c:\users\joe\documents\visual studio 2012\projects\consoleapplication6\consoleapplication6\timxmlrpc.cpp(125): error C2065: '_size' : undeclared identifier
1>c:\users\joe\documents\visual studio 2012\projects\consoleapplication6\consoleapplication6\timxmlrpc.cpp(129): error C2027: use of undefined type 'XmlRpcValue'
1>          c:\users\joe\documents\visual studio 2012\projects\consoleapplication6\consoleapplication6\timxmlrpc.h(75) : see declaration of 'XmlRpcValue'
1>c:\users\joe\documents\visual studio 2012\projects\consoleapplication6\consoleapplication6\timxmlrpc.cpp(129): error C2065: 'ValueArray' : undeclared identifier
1>c:\users\joe\documents\visual studio 2012\projects\consoleapplication6\consoleapplication6\timxmlrpc.cpp(129): error C2065: 'other' : undeclared identifier
1>c:\users\joe\documents\visual studio 2012\projects\consoleapplication6\consoleapplication6\timxmlrpc.cpp(130): error C2448: '==' : function-style initializer appears to be a function definition
1>c:\users\joe\documents\visual studio 2012\projects\consoleapplication6\consoleapplication6\timxmlrpc.cpp(141): error C2027: use of undefined type 'XmlRpcValue'
1>          c:\users\joe\documents\visual studio 2012\projects\consoleapplication6\consoleapplication6\timxmlrpc.h(75) : see declaration of 'XmlRpcValue'
1>c:\users\joe\documents\visual studio 2012\projects\consoleapplication6\consoleapplication6\timxmlrpc.cpp(141): fatal error C1903: unable to recover from previous error(s); stopping compilation
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
jste89
  • 426
  • 4
  • 15
  • 2
    Are you linking to the library which provides `XmlRpcClient`? – simonc Jul 11 '13 at 16:24
  • If you're not sure how to specify that you want to link to an external library, [this previous post](http://stackoverflow.com/q/1114914/311966) may be helpful. – simonc Jul 11 '13 at 16:33
  • Not sure. I'm new to Visual-Studio, i'v only programmed C in vi/vim before. The files are all in the same dir and they are included at the top of the file ( #include "timxmlrpc.h" ). Having read that comment, i should say that the source i downloaded to make RPC calls doesn't include a .lib file. Would i be right in thinking that this requires a file that i haven't included? – jste89 Jul 11 '13 at 16:34
  • `#include` tells the pre-processor where to find declarations of classes & functions. This is all that is required for the compiler to run. After compilation, you need to link the object code generated by the compiler into executable code. This involves resolving the location of each function call - either as a jump within your binary or as a call to a separate library. For this to work with additional libraries, you have to tell the linker what libraries to use and where to find them. – simonc Jul 11 '13 at 16:40
  • If you don't have a .lib (or .dll) for your RPC code, it sounds like you're expected to compile it yourself. You could then include it in your project and skip worrying about linker settings. Or, if there is a non-trivial amount of code, look for a makefile or csproj that'll help you build it as its own library then look at the link in my earlier post to see how to link to this library. – simonc Jul 11 '13 at 16:43
  • Good information. I'll edit in what I've done so far and post the errors i have now. I think i need XmlRpcClient .lib also but no idea where to find that at all. Might have to go back to square one... – jste89 Jul 11 '13 at 17:33
  • 1
    Based on your new errors, I'm afraid it looks like you've picked a library that's poorly done. Protecting header files against multiple inclusion is beginner stuff, so if they got that wrong, what other problems are lurking? – Ben Voigt Jul 11 '13 at 17:41

1 Answers1

0

Is there an XmlPrcClient .lib file on your machine somewhere?

If so, you will need to add the .lib to the linker settings, under the linker | input | additional dependencies in the project settings.

If not, you need to get one from somewhere. There is a discussion about XmlRpc here

And from a manual:

don’t forget to download and include timxmlrpc.h, timxmlrpc.cpp. Also, remember to add wininet.lib to your CPP Client project

If you have a timxmlrpc.cpp file you must include that in your project too.

Community
  • 1
  • 1
doctorlove
  • 18,872
  • 2
  • 46
  • 62