0

我正在编写一个程序,该程序采用磁力链接,然后使用 RCP 调用远程客户端并在 Deluge 中打开磁力链接。我使用 xmlrpcc4win 作为我的 RPC 库。到目前为止,我可能已经花了一个半小时的时间,大部分时间都在谷歌上搜索这个错误,几乎没有运气。

我的代码如下:

// 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;
}

到目前为止,我构建代码时的输出如下:

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

好的,现在我已经包含了 timxmlrpc.cpp 并将 wininet.lib 链接到我的项目。我现在得到以下...

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

1 回答 1

0

您的机器上某处是否有 XmlPrcClient .lib 文件?

如果是这样,您需要将 .lib 添加到链接器设置中,在链接器 | 下。输入 | 项目设置中的其他依赖项。

如果没有,你需要从某个地方得到一个。这里有关于 XmlRpc 的讨论

并从手册

不要忘记下载并包含 timxmlrpc.h、timxmlrpc.cpp。另外,记得将 wininet.lib 添加到您的 CPP 客户端项目中

如果你有一个 timxmlrpc.cpp 文件,你也必须将它包含在你的项目中。

于 2013-07-11T16:38:37.933 回答