Paho C ++ Lib集成:未解决的外部错误

问题描述 投票:0回答:1

我正在尝试在我自己的C ++项目(Visual Studio 2017)中使用Paho C ++库。我已经构建并安装了Paho C库和Paho C ++库,如前所述here。到目前为止,一切都很好。之后,我在Visual Studio 2017中创建了一个新的(空白)C ++项目,并在项目属性中应用了以下更改:

  1. 在Tab C / C ++中/常规:在“其他包含目录”中,我添加了两个包含路径(来自paho c和paho c ++安装路径):

Additional Include Directories

  1. 在标签链接器中/常规:在“其他库目录”中,我将路径添加到lib文件夹(来自paho c和paho c ++安装路径):

Additional Library Directories

  1. 在选项卡链接器/输入中:在“其他依赖项”中,我添加了paho c和paho c ++库的库名称。

enter image description here

  1. 此外,我已经将paho-mqtt3c.dll复制到了我的C ++项目的Debug文件夹中,并且包含了topic_publish.cpp示例文件(作为我的主文件)。

问题:如果我尝试构建应用程序,则出现20个链接错误。

1>------ Build started: Project: PahoCppLibTest, Configuration: Debug Win32 ------
1>Main.cpp
1>paho-mqttpp3-static.lib(async_client.obj) : error LNK2019: unresolved external symbol _MQTTAsync_setDisconnected referenced in function "public: void __thiscall mqtt::async_client::set_disconnected_handler(class std::function<void __cdecl(class mqtt::properties const &,enum mqtt::ReasonCode)>)" (?set_disconnected_handler@async_client@mqtt@@QAEXV?$function@$$A6AXABVproperties@mqtt@@W4ReasonCode@2@@Z@std@@@Z)
1>paho-mqttpp3-static.lib(async_client.obj) : error LNK2019: unresolved external symbol _MQTTAsync_setCallbacks referenced in function "public: virtual void __thiscall mqtt::async_client::set_callback(class mqtt::callback &)" (?set_callback@async_client@mqtt@@UAEXAAVcallback@2@@Z)
1>paho-mqttpp3-static.lib(async_client.obj) : error LNK2019: unresolved external symbol _MQTTAsync_setConnectionLostCallback referenced in function "public: void __thiscall mqtt::async_client::set_connection_lost_handler(class std::function<void __cdecl(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)>)" (?set_connection_lost_handler@async_client@mqtt@@QAEXV?$function@$$A6AXABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z@std@@@Z)
1>paho-mqttpp3-static.lib(async_client.obj) : error LNK2019: unresolved external symbol _MQTTAsync_setMessageArrivedCallback referenced in function "public: void __thiscall mqtt::async_client::set_message_callback(class std::function<void __cdecl(class std::shared_ptr<class mqtt::message const >)>)" (?set_message_callback@async_client@mqtt@@QAEXV?$function@$$A6AXV?$shared_ptr@$$CBVmessage@mqtt@@@std@@@Z@std@@@Z)
1>paho-mqttpp3-static.lib(async_client.obj) : error LNK2019: unresolved external symbol _MQTTAsync_setConnected referenced in function "public: virtual void __thiscall mqtt::async_client::set_callback(class mqtt::callback &)" (?set_callback@async_client@mqtt@@UAEXAAVcallback@2@@Z)
1>paho-mqttpp3-static.lib(async_client.obj) : error LNK2019: unresolved external symbol _MQTTAsync_reconnect referenced in function "public: virtual class std::shared_ptr<class mqtt::token> __thiscall mqtt::async_client::reconnect(void)" (?reconnect@async_client@mqtt@@UAE?AV?$shared_ptr@Vtoken@mqtt@@@std@@XZ)
1>paho-mqttpp3-static.lib(async_client.obj) : error LNK2019: unresolved external symbol _MQTTAsync_createWithOptions referenced in function "public: __thiscall mqtt::async_client::async_client(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??0async_client@mqtt@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0H0@Z)
1>paho-mqttpp3-static.lib(async_client.obj) : error LNK2019: unresolved external symbol _MQTTAsync_connect referenced in function "public: virtual class std::shared_ptr<class mqtt::token> __thiscall mqtt::async_client::connect(class mqtt::connect_options)" (?connect@async_client@mqtt@@UAE?AV?$shared_ptr@Vtoken@mqtt@@@std@@Vconnect_options@2@@Z)
1>paho-mqttpp3-static.lib(async_client.obj) : error LNK2019: unresolved external symbol _MQTTAsync_disconnect referenced in function "public: virtual class std::shared_ptr<class mqtt::token> __thiscall mqtt::async_client::disconnect(class mqtt::disconnect_options)" (?disconnect@async_client@mqtt@@UAE?AV?$shared_ptr@Vtoken@mqtt@@@std@@Vdisconnect_options@2@@Z)
1>paho-mqttpp3-static.lib(async_client.obj) : error LNK2019: unresolved external symbol _MQTTAsync_isConnected referenced in function "public: virtual bool __thiscall mqtt::async_client::is_connected(void)const " (?is_connected@async_client@mqtt@@UBE_NXZ)
1>paho-mqttpp3-static.lib(async_client.obj) : error LNK2019: unresolved external symbol _MQTTAsync_subscribe referenced in function "public: virtual class std::shared_ptr<class mqtt::token> __thiscall mqtt::async_client::subscribe(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,int,class mqtt::subscribe_options const &)" (?subscribe@async_client@mqtt@@UAE?AV?$shared_ptr@Vtoken@mqtt@@@std@@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@4@HABVsubscribe_options@2@@Z)
1>paho-mqttpp3-static.lib(async_client.obj) : error LNK2019: unresolved external symbol _MQTTAsync_subscribeMany referenced in function "public: virtual class std::shared_ptr<class mqtt::token> __thiscall mqtt::async_client::subscribe(class std::shared_ptr<class mqtt::string_collection const >,class std::vector<int,class std::allocator<int> > const &,class std::vector<class mqtt::subscribe_options,class std::allocator<class mqtt::subscribe_options> > const &)" (?subscribe@async_client@mqtt@@UAE?AV?$shared_ptr@Vtoken@mqtt@@@std@@V?$shared_ptr@$$CBVstring_collection@mqtt@@@4@ABV?$vector@HV?$allocator@H@std@@@4@ABV?$vector@Vsubscribe_options@mqtt@@V?$allocator@Vsubscribe_options@mqtt@@@std@@@4@@Z)
1>paho-mqttpp3-static.lib(async_client.obj) : error LNK2019: unresolved external symbol _MQTTAsync_unsubscribe referenced in function "public: virtual class std::shared_ptr<class mqtt::token> __thiscall mqtt::async_client::unsubscribe(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?unsubscribe@async_client@mqtt@@UAE?AV?$shared_ptr@Vtoken@mqtt@@@std@@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@4@@Z)
1>paho-mqttpp3-static.lib(async_client.obj) : error LNK2019: unresolved external symbol _MQTTAsync_unsubscribeMany referenced in function "public: virtual class std::shared_ptr<class mqtt::token> __thiscall mqtt::async_client::unsubscribe(class std::shared_ptr<class mqtt::string_collection const >)" (?unsubscribe@async_client@mqtt@@UAE?AV?$shared_ptr@Vtoken@mqtt@@@std@@V?$shared_ptr@$$CBVstring_collection@mqtt@@@4@@Z)
1>paho-mqttpp3-static.lib(async_client.obj) : error LNK2019: unresolved external symbol _MQTTAsync_sendMessage referenced in function "public: virtual class std::shared_ptr<class mqtt::delivery_token> __thiscall mqtt::async_client::publish(class std::shared_ptr<class mqtt::message const >)" (?publish@async_client@mqtt@@UAE?AV?$shared_ptr@Vdelivery_token@mqtt@@@std@@V?$shared_ptr@$$CBVmessage@mqtt@@@4@@Z)
1>paho-mqttpp3-static.lib(async_client.obj) : error LNK2019: unresolved external symbol _MQTTAsync_freeMessage referenced in function "private: static int __cdecl mqtt::async_client::on_message_arrived(void *,char *,int,struct MQTTAsync_message *)" (?on_message_arrived@async_client@mqtt@@CAHPAXPADHPAUMQTTAsync_message@@@Z)
1>paho-mqttpp3-static.lib(async_client.obj) : error LNK2019: unresolved external symbol _MQTTAsync_free referenced in function "private: static int __cdecl mqtt::async_client::on_message_arrived(void *,char *,int,struct MQTTAsync_message *)" (?on_message_arrived@async_client@mqtt@@CAHPAXPADHPAUMQTTAsync_message@@@Z)
1>paho-mqttpp3-static.lib(async_client.obj) : error LNK2019: unresolved external symbol _MQTTAsync_destroy referenced in function "public: virtual __thiscall mqtt::async_client::~async_client(void)" (??1async_client@mqtt@@UAE@XZ)
1>paho-mqttpp3-static.lib(async_client.obj) : error LNK2019: unresolved external symbol _MQTTAsync_strerror referenced in function "public: static class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl mqtt::exception::error_str(int)" (?error_str@exception@mqtt@@SA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@H@Z)
1>C:\mqtt\projects\PahoCppLibTest\Debug\PahoCppLibTest.exe : fatal error LNK1120: 19 unresolved externals
1>Done building project "PahoCppLibTest.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

编辑:该库通过包含它来使用,如下所示:

#include "mqtt/async_client.h"

这是我正在使用的主要代码(它是来自paho c ++库的“ topic_publish.cpp”示例:]]

// topic_publish.cpp
//
// This is a Paho MQTT C++ client, sample application.
//
// It's an example of how to send messages as an MQTT publisher using the
// C++ asynchronous client interface using a 'topic' object to repeatedly
// send data to the same topic.
//
// The sample demonstrates:
//  - Connecting to an MQTT server/broker
//  - Publishing messages
//  - Use of the 'topic' class
//

/*******************************************************************************
 * Copyright (c) 2019 Frank Pagliughi <[email protected]>
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * and Eclipse Distribution License v1.0 which accompany this distribution.
 *
 * The Eclipse Public License is available at
 *    http://www.eclipse.org/legal/epl-v10.html
 * and the Eclipse Distribution License is available at
 *   http://www.eclipse.org/org/documents/edl-v10.php.
 *
 * Contributors:
 *    Frank Pagliughi - initial implementation and documentation
 *******************************************************************************/

#include <iostream>
#include <cstdlib>
#include <string>
#include <thread>   // For sleep
#include <atomic>
#include <chrono>
#include <cstring>
#include "mqtt/async_client.h"

using namespace std;

const string DFLT_SERVER_ADDRESS{ "tcp://localhost:1883" };

const string TOPIC{ "test" };
const int QOS = 1;

const char* PAYLOADS[] = {
    "Hello World!",
    "Hi there!",
    "Is anyone listening?",
    "Someone is always listening.",
    nullptr
};

const auto TIMEOUT = std::chrono::seconds(10);

/////////////////////////////////////////////////////////////////////////////

int main(int argc, char* argv[])
{
    string address = (argc > 1) ? string(argv[1]) : DFLT_SERVER_ADDRESS;

    cout << "Initializing for server '" << address << "'..." << endl;
    mqtt::async_client cli(address, "");

    cout << "  ...OK" << endl;

    try {
        cout << "\nConnecting..." << endl;
        cli.connect()->wait();
        cout << "  ...OK" << endl;

        cout << "\nPublishing messages..." << endl;

        mqtt::topic top(cli, "test", QOS);
        mqtt::token_ptr tok;

        size_t i = 0;
        while (PAYLOADS[i]) {
            tok = top.publish(PAYLOADS[i++]);
        }
        tok->wait();    // Just wait for the last one to complete.
        cout << "OK" << endl;

        // Disconnect
        cout << "\nDisconnecting..." << endl;
        cli.disconnect()->wait();
        cout << "  ...OK" << endl;
    }
    catch (const mqtt::exception& exc) {
        cerr << exc.what() << endl;
        return 1;
    }

    return 0;
}

我建议问题出在paho-mqttpp3-static.lib文件中,但我不知道如何解决。有什么建议吗?

我正在尝试在我自己的C ++项目(Visual Studio 2017)中使用Paho C ++库。如此处所述,我已经构建并安装了Paho C库和Paho C ++库。到目前为止,一切都很好。之后,...

c++ dll mqtt paho pahocpp
1个回答
0
投票

它终于按照fpagliughi(github)的回答工作了:

© www.soinside.com 2019 - 2024. All rights reserved.