在 visual studio 中使用 vcpkg 使用 paho-mqtt x64 时出错

Error using paho-mqtt x64 using vcpkg in visual studio

我已经使用 vcpkg 安装了 paho-mqttpp3:x64-windows,运行在 Visual Studio 中使用 x64 中的构建选项安装了以下代码。

#include <iostream>
#include "mqtt/async_client.h"

int main()
{
    std::cout << "Hello World!\n";
}

当我在上面的代码中 运行 时,它会生成以下错误

> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(67):
> error C3861: 'visibility': identifier not found
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(67):
> error C4430: missing type specifier - int assumed. Note: C++ does not
> support default-int
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(67):
> error C2059: syntax error: 'const'
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(85):
> error C3861: 'visibility': identifier not found
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(85):
> error C4430: missing type specifier - int assumed. Note: C++ does not
> support default-int
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(85):
> error C2374: '__attribute__': redefinition; multiple initialization
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(67):
> note: see declaration of '__attribute__'
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(85):
> error C2448: '__attribute__': function-style initializer appears to be
> a function definition
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(109):
> error C3646: 'data': unknown override specifier
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(109):
> error C4430: missing type specifier - int assumed. Note: C++ does not
> support default-int
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(110):
> error C3646: 'value': unknown override specifier
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(110):
> error C4430: missing type specifier - int assumed. Note: C++ does not
> support default-int
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(123):
> error C2143: syntax error: missing ';' before '*'
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(123):
> error C4430: missing type specifier - int assumed. Note: C++ does not
> support default-int
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(123):
> error C2238: unexpected token(s) preceding ';'
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(141):
> error C3861: 'visibility': identifier not found
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(141):
> error C4430: missing type specifier - int assumed. Note: C++ does not
> support default-int
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(141):
> error C2374: '__attribute__': redefinition; multiple initialization
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(67):
> note: see declaration of '__attribute__'
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(141):
> error C2448: '__attribute__': function-style initializer appears to be
> a function definition
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(141):
> error C2143: syntax error: missing ',' before '*'
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(164):
> error C3861: 'visibility': identifier not found
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(164):
> error C4430: missing type specifier - int assumed. Note: C++ does not
> support default-int
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(164):
> error C2374: '__attribute__': redefinition; multiple initialization
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(67):
> note: see declaration of '__attribute__'
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(164):
> error C2448: '__attribute__': function-style initializer appears to be
> a function definition
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(171):
> error C3861: 'visibility': identifier not found
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(171):
> error C4430: missing type specifier - int assumed. Note: C++ does not
> support default-int
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(171):
> error C2374: '__attribute__': redefinition; multiple initialization
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(67):
> note: see declaration of '__attribute__'
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(171):
> error C2146: syntax error: missing ';' before identifier
> 'MQTTProperties'
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(179):
> error C3861: 'visibility': identifier not found
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(179):
> error C4430: missing type specifier - int assumed. Note: C++ does not
> support default-int
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(179):
> error C2374: '__attribute__': redefinition; multiple initialization
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(67):
> note: see declaration of '__attribute__'
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(179):
> error C2448: '__attribute__': function-style initializer appears to be
> a function definition
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(188):
> error C3861: 'visibility': identifier not found
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(188):
> error C4430: missing type specifier - int assumed. Note: C++ does not
> support default-int
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(188):
> error C2374: '__attribute__': redefinition; multiple initialization
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(67):
> note: see declaration of '__attribute__'
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(188):
> error C2448: '__attribute__': function-style initializer appears to be
> a function definition
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(196):
> error C3861: 'visibility': identifier not found
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(196):
> error C4430: missing type specifier - int assumed. Note: C++ does not
> support default-int
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(196):
> error C2374: '__attribute__': redefinition; multiple initialization
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(67):
> note: see declaration of '__attribute__'
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(196):
> error C2448: '__attribute__': function-style initializer appears to be
> a function definition
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(206):
> error C3861: 'visibility': identifier not found
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(206):
> error C4430: missing type specifier - int assumed. Note: C++ does not
> support default-int
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(206):
> error C2374: '__attribute__': redefinition; multiple initialization
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(67):
> note: see declaration of '__attribute__'
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(206):
> error C2448: '__attribute__': function-style initializer appears to be
> a function definition
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(214):
> error C3861: 'visibility': identifier not found
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(214):
> error C4430: missing type specifier - int assumed. Note: C++ does not
> support default-int
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(214):
> error C2374: '__attribute__': redefinition; multiple initialization
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(67):
> note: see declaration of '__attribute__'
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(214):
> error C2146: syntax error: missing ';' before identifier
> 'MQTTProperty'
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(223):
> error C3861: 'visibility': identifier not found
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(223):
> error C4430: missing type specifier - int assumed. Note: C++ does not
> support default-int
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(223):
> error C2374: '__attribute__': redefinition; multiple initialization
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(67):
> note: see declaration of '__attribute__'
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(223):
> error C2146: syntax error: missing ';' before identifier
> 'MQTTProperty'
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttreasoncodes.h(83):
> error C3861: 'visibility': identifier not found
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttreasoncodes.h(83):
> error C4430: missing type specifier - int assumed. Note: C++ does not
> support default-int
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttreasoncodes.h(83):
> error C2374: '__attribute__': redefinition; multiple initialization
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(67):
> note: see declaration of '__attribute__'
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttreasoncodes.h(83):
> error C2059: syntax error: 'const'
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttclientpersistence.h(223):
> error C3646: 'popen': unknown override specifier
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttclientpersistence.h(223):
> error C4430: missing type specifier - int assumed. Note: C++ does not
> support default-int
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttclientpersistence.h(227):
> error C3646: 'pclose': unknown override specifier
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttclientpersistence.h(227):
> error C4430: missing type specifier - int assumed. Note: C++ does not
> support default-int
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttclientpersistence.h(231):
> error C3646: 'pput': unknown override specifier
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttclientpersistence.h(231):
> error C4430: missing type specifier - int assumed. Note: C++ does not
> support default-int
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttclientpersistence.h(235):
> error C3646: 'pget': unknown override specifier
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttclientpersistence.h(235):
> error C4430: missing type specifier - int assumed. Note: C++ does not
> support default-int
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttclientpersistence.h(239):
> error C3646: 'premove': unknown override specifier
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttclientpersistence.h(239):
> error C4430: missing type specifier - int assumed. Note: C++ does not
> support default-int
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttclientpersistence.h(243):
> error C3646: 'pkeys': unknown override specifier
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttclientpersistence.h(243):
> error C4430: missing type specifier - int assumed. Note: C++ does not
> support default-int
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttclientpersistence.h(247):
> error C3646: 'pclear': unknown override specifier
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttclientpersistence.h(247):
> error C4430: missing type specifier - int assumed. Note: C++ does not
> support default-int
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttclientpersistence.h(251):
> error C3646: 'pcontainskey': unknown override specifier
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttclientpersistence.h(251):
> error C4430: missing type specifier - int assumed. Note: C++ does not
> support default-int
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(233):
> error C3861: 'visibility': identifier not found
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(233):
> error C4430: missing type specifier - int assumed. Note: C++ does not
> support default-int
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(233):
> error C2374: '__attribute__': redefinition; multiple initialization
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(67):
> note: see declaration of '__attribute__'
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(233):
> error C2448: '__attribute__': function-style initializer appears to be
> a function definition
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(233):
> error C2065: 'MQTTAsync_init_options': undeclared identifier
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(233):
> error C2065: 'inits': undeclared identifier
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(233):
> error C2182: 'MQTTAsync_global_init': illegal use of type 'void'
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(346):
> error C2061: syntax error: identifier 'MQTTAsync_message'
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(366):
> error C2061: syntax error: identifier 'MQTTAsync_token'
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(424):
> error C3861: 'visibility': identifier not found
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(424):
> error C4430: missing type specifier - int assumed. Note: C++ does not
> support default-int
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(424):
> error C2374: '__attribute__': redefinition; multiple initialization
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(67):
> note: see declaration of '__attribute__'
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(424):
> error C2448: '__attribute__': function-style initializer appears to be
> a function definition
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(424):
> error C2065: 'MQTTAsync': undeclared identifier
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(424):
> error C2146: syntax error: missing ')' before identifier 'handle'
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(431):
> error C3646: 'token': unknown override specifier
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(431):
> error C4430: missing type specifier - int assumed. Note: C++ does not
> support default-int
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(447):
> error C3646: 'token': unknown override specifier
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(447):
> error C4430: missing type specifier - int assumed. Note: C++ does not
> support default-int
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(466):
> error C3646: 'token': unknown override specifier
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(466):
> error C4430: missing type specifier - int assumed. Note: C++ does not
> support default-int
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(477):
> error C3646: 'message': unknown override specifier
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(477):
> error C4430: missing type specifier - int assumed. Note: C++ does not
> support default-int
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(497):
> error C3646: 'token': unknown override specifier
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(497):
> error C4430: missing type specifier - int assumed. Note: C++ does not
> support default-int
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(512):
> error C3646: 'message': unknown override specifier
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(512):
> error C4430: missing type specifier - int assumed. Note: C++ does not
> support default-int
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(543):
> error C2061: syntax error: identifier 'MQTTAsync_successData'
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(556):
> error C2061: syntax error: identifier 'MQTTAsync_successData5'
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(568):
> error C2061: syntax error: identifier 'MQTTAsync_failureData'
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(580):
> error C2061: syntax error: identifier 'MQTTAsync_failureData5'
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(594):
> error C2143: syntax error: missing ';' before '*'
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(594):
> error C4430: missing type specifier - int assumed. Note: C++ does not
> support default-int
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(594):
> error C2238: unexpected token(s) preceding ';'
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(600):
> error C2143: syntax error: missing ';' before '*'
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(600):
> error C4430: missing type specifier - int assumed. Note: C++ does not
> support default-int
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(600):
> error C2238: unexpected token(s) preceding ';'
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(612):
> error C3646: 'token': unknown override specifier
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(612):
> error C4430: missing type specifier - int assumed. Note: C++ does not
> support default-int
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(618):
> error C2143: syntax error: missing ';' before '*'
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(618):
> error C4430: missing type specifier - int assumed. Note: C++ does not
> support default-int
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(618):
> error C2238: unexpected token(s) preceding ';'
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(624):
> error C2143: syntax error: missing ';' before '*'
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(624):
> error C4430: missing type specifier - int assumed. Note: C++ does not
> support default-int
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(624):
> error C2238: unexpected token(s) preceding ';'
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(677):
> error C3861: 'visibility': identifier not found
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(677):
> error C4430: missing type specifier - int assumed. Note: C++ does not
> support default-int
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(677):
> error C2374: '__attribute__': redefinition; multiple initialization
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(67):
> note: see declaration of '__attribute__'
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(677):
> error C2448: '__attribute__': function-style initializer appears to be
> a function definition
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(677):
> error C2065: 'MQTTAsync': undeclared identifier
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(677):
> error C2146: syntax error: missing ')' before identifier 'handle'
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(700):
> error C3861: 'visibility': identifier not found
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(700):
> error C4430: missing type specifier - int assumed. Note: C++ does not
> support default-int
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(700):
> error C2374: '__attribute__': redefinition; multiple initialization
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(67):
> note: see declaration of '__attribute__'
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(700):
> error C2448: '__attribute__': function-style initializer appears to be
> a function definition
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(700):
> error C2065: 'MQTTAsync': undeclared identifier
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(700):
> error C2146: syntax error: missing ')' before identifier 'handle'
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(724):
> error C3861: 'visibility': identifier not found
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(724):
> error C4430: missing type specifier - int assumed. Note: C++ does not
> support default-int
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(724):
> error C2374: '__attribute__': redefinition; multiple initialization
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(67):
> note: see declaration of '__attribute__'
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(724):
> error C2448: '__attribute__': function-style initializer appears to be
> a function definition
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(724):
> error C2065: 'MQTTAsync': undeclared identifier
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(724):
> error C2146: syntax error: missing ')' before identifier 'handle'
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(746):
> error C3861: 'visibility': identifier not found
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(746):
> error C4430: missing type specifier - int assumed. Note: C++ does not
> support default-int
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(746):
> error C2374: '__attribute__': redefinition; multiple initialization
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttproperties.h(67):
> note: see declaration of '__attribute__'
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(746):
> error C2448: '__attribute__': function-style initializer appears to be
> a function definition
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(746):
> error C2065: 'MQTTAsync': undeclared identifier
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(746):
> error C2146: syntax error: missing ')' before identifier 'handle'
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(761):
> error C3861: 'visibility': identifier not found
> 1>d:\vcpkg\packages\paho-mqtt_x64-windows\include\paho-mqtt\mqttasync.h(761):
> fatal error C1003: error count exceeds 100; stopping compilation

但是当我使用 vcpkg 安装 paho-mqttpp3:x86-windows 并且 运行 在 Visual Studio 中使用相同的代码在 x86 中使用构建选项。 获取成功运行.

#include <iostream>
#include "mqtt/async_client.h"

int main()
{
    std::cout << "Hello World!\n";
}

OS - Windows 10 64 位主页

Visual Studio - 15.9.19

paho-mqtt 使用 vcpkg 安装。

我发现这个问题的解决方案是您必须更改 MQTT 文件中的一些内容。

要对 paho-mqtt 文件夹中的以下文件的内容进行更改。在我的例子中,它在 D:\vcpkg\installed\x64-windows\include\paho-mqtt

里面

MQTTAsync

MQTTClient

MQTT 属性

MQTTReasonCodes

在以上所有文件中修改以下内容。

#if defined(WIN32) || defined(WIN64)
  #define DLLImport __declspec(dllimport)
  #define DLLExport __declspec(dllexport)
#else
  #define DLLImport extern
  #define DLLExport  __attribute__ ((visibility ("default")))
#endif

Macro WIN32 and WIN64 should be changed to _WIN32 and _WIN64

你会发现它是这样的:

#if defined(WIN32) || defined(WIN64)

改为

#if defined(_WIN32) || defined(_WIN64)

OR

注意:如果您已经执行了上述步骤,请不要执行以下步骤。

您可以在 Visual Studio 的项目 属性 的 预处理器目录 中添加 WIN64

转到解决方案资源管理器 --> 属性 --> C/C++ --> 预处理器。

预处理器目录

中添加WIN64