Issue
There are a few questions out there about __declspec(dllexport)
, but none seem to fit my use case:
- Source code was originally written for Windows and uses
__declspec(dllexport)
. - Would like to recompile for a Linux target without modifying the source.
I am trying to use GCC 11.4, which mentions:
You can use
__declspec(dllexport)
as a synonym for__attribute__ ((dllexport))
for compatibility with other compilers.
I can't seem to get this to work, however.
error: expected constructor, destructor, or type conversion before ‘(’ token
8 | #define dll_export __declspec(dllexport)
error: ‘dllexport’ was not declared in this scope
23 | void __declspec(dllexport) _Err_msg(int err, char*& msg);
Hoping that there are some magic GCC flags that I am missing, or another kind of non-invasive shim I could use to get this to compile for Linux. Any help appreciated!
Solution
How about -D option?
-D name=definition
The contents of definition are tokenized and processed as if they appeared during translation phase three in a ‘#define’ directive. In particular, the definition is truncated by embedded newline characters.
gcc -D__declspec(dllexport)=__attribute__((dllexport)) ...
Similar for other Windows specific stuff
Answered By - Severin Pappadeux Answer Checked By - Cary Denson (WPSolving Admin)