我很好奇能夠在Linux編譯的C++代碼中使用Windows中編譯的最原始的DLL庫。假設有問題的庫不是來自Windows核心的可怕的專有;關於爲什麼windows'.dll不適用於linux的具體細節
...只是一個與像假的API(這裏是頭文件和實現):
// 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;
}
}
該庫將有不超過<的iostream >其他依賴,不是嗎?
的Linux編譯的.cpp將包含以下內容:
// 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.
因此,爲了清楚我的問題:什麼使用dependenceless .DLL庫MathDuncsDll
只是停止++編譯和鏈接工具像另一個.so?也許,另一個調用語法?或者,也許整個鏈接過程是不同的? (我想聽聽具體細節,不僅僅是含糊不清的「這些操作系統在本質上是不同的」,「不可能在另一個平臺上使用某些東西」)需要克服這些差異需要多少努力(I假設我們沒有使用Wine)?
非常感謝您提前!
您可能想要谷歌「NdisWrapper」,一個Linux工具,它可以加載實際的Windows驅動程序。這表明你絕對可以從Linux調用Windows代碼,但不容易。 – MSalters