I am planning to use libraries in my C++ program. Development is happening on Linux but application is designed to compile on both Linux and Windows. I understand direct equivalent for shared libraries(.so) in windows is DLL, right?
In Linux using g++, I can create shared library using -fPIC and -shared flags. AFAIK, there is no other code change required for a shared library. But things are different in a Windows DLL. There I should specify the functions which have to be exported using dllexport, right?
My question is how do I manage this situation? I mean dllexport is invalid in Linux and the compiler will give an error. But it is required in Windows. So how do I write a function which will compile on both platforms without any code change?
Compilers used
- g++ – LINUX
- VC++ – Windows
Any help would be great!
We specify
__declspec(dllexport)for class:You can then check for platform and only define the macro on windows. E.g.:
We mostly build static libraries so there might be more stuff to do for dynamic libs but the concept is the same – use preprocessor macro to define string that you need to insert into Windows code.