Visual Studio Paho MQTT Error C2238 unexpected token(s) preceding ‘;’
If you’re receiving errors like the following when trying to build a project in Visual Studio 2017 using the Paho C client:
Error C2238 unexpected token(s) preceding ';'
Then there is a quick fix, the problem seems to revolve around the following for DLLImport & DLLExport in the Paho header files:
#if defined(WIN32) || defined(WIN64) #define DLLImport __declspec(dllimport) #define DLLExport __declspec(dllexport) #else #define DLLImport extern #define DLLExport __attribute__ ((visibility ("default"))) #endif
The catch here is that neither WIN32 nor WIN64 will be defined as instead either _WIN32 or _WIN64 will be defined.
So a quick fix is to define either WIN32 or WIN64 in your project’s ‘Preprocessor Definitions’ depending on whether you are targeting x86 (32bit) or x64 (64bit).
Here are some of the other errors you might see when you have this problem:
error C3861: 'visibility': identifier not found error C4430: missing type specifier - int assumed. Note: C++ does not support default-int error C2059: syntax error: 'const' error C3861: 'visibility': identifier not found error C4430: missing type specifier - int assumed. Note: C++ does not support default-int error C2374: '__attribute__': redefinition; multiple initialization note: see declaration of '__attribute__' error C2448: '__attribute__': function-style initializer appears to be a function definition error C3646: 'data': unknown override specifier error C4430: missing type specifier - int assumed. Note: C++ does not support default-int error C3646: 'value': unknown override specifier error C4430: missing type specifier - int assumed. Note: C++ does not support default-int error C2143: syntax error: missing ';' before '*' error C4430: missing type specifier - int assumed. Note: C++ does not support default-int error C2238: unexpected token(s) preceding ';' error C3861: 'visibility': identifier not found error C4430: missing type specifier - int assumed. Note: C++ does not support default-int error C2374: '__attribute__': redefinition; multiple initialization note: see declaration of '__attribute__' error C2448: '__attribute__': function-style initializer appears to be a function definition error C2143: syntax error: missing ',' before '*' error C3861: 'visibility': identifier not found error C4430: missing type specifier - int assumed. Note: C++ does not support default-int