I am curious about being able to use the most primitive ever DLL-library compiled in Windows, in Linux-compiled C++ code. Let's assume that library in question is not the monstrous proprietary something from Windows core;
…just one with phony API like (here are both header and implementation):
// MathFuncsDll.h
namespace MathFuncs
{
class MyMathFuncs
{
public:
// Returns a + b
static __declspec(dllexport) double Add(double a, double b);
// Returns a - b
static __declspec(dllexport) double Subtract(double a, double b);
};
}
// MathFuncsDll.cpp
#include "MathFuncsDll.h"
using namespace std;
namespace MathFuncs
{
double MyMathFuncs::Add(double a, double b)
{
return a + b;
}
double MyMathFuncs::Subtract(double a, double b)
{
return a - b;
}
}
This library would have no dependencies other than <iostream>, would it?
Linux-compiled .cpp would contain the following:
// MyExecRefsDll.cpp
// compile with: /EHsc /link MathFuncsDll.lib
#include <iostream>
#include "MathFuncsDll.h"
using namespace std;
int main()
{
double a = 7.4;
int b = 99;
cout << "a + b = " <<
MathFuncs::MyMathFuncs::Add(a, b) << endl;
cout << "a - b = " <<
MathFuncs::MyMathFuncs::Subtract(a, b) << endl;
return 0;
}
Samples were taken from amazing MSDN tutorial.
So, to make my question clear: what stops linux compiler and linking tools from using dependenceless .dll library MathDuncsDll
just like another .so? Maybe, another call syntax? Or maybe the whole linking process is different? (I'd like to hear specifics, not just vague "these OS'es are fundamentionally different" and "it is impossible to use something from one platform on another") How much effort will these differences require to be overcome (I assume we're not using Wine)?
Thank you very much in advance!