How to fix GCC error: expected constructor, destructor, or type conversion before __declspec(dllexport)
Problem:
When trying to compile an application on Linux, you see a compiler error message like
error_example.cpp
myheader.h:23:12: error: expected constructor, destructor, or type conversion before ‘(’ token
23 | __declspec(dllexport) int myfunc(Solution
__declspec(dllexport) is a Windows-specific feature and not available on Linux. In order to fix it in a compatible way, add this code either in a header that is included in every file containing __declspec(dllexport) or add it in each file where the error occurs:
compat_declspec.h
#ifdef __linux__
#define __declspec(v)
#endifThis will basically ignore any __declspec() call on the preprocessor level.
Check out similar posts by category:
C/C++, GCC Errors
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow