跨平台动态链接(Windows到linux) [英] Cross platform dynamic linking (Windows to linux)
问题描述
现在是链接到已经为Windows编写的.dll的时候了。如果我可以推迟动态链接库的转换,这将是一件好事。其他Windows应用程序连接到这个库,如下所示:
HINSTANCE dll;
dll = LoadLibraryA(filename);
// ...
libFuncPtr =(libFuncPtr)GetProcAddress(dll,libFunc);
我想知道这些功能是否有通用模拟,或者是开始放弃的时候在我的系统中具体的预处理指令? Developemt的当前优先级是Windows,据了解,Linux构建的Linux端口必须是Linux端口,但我希望尽可能使调用代码为通用。
开始删除系统特定的预处理指令。
您可以编写一个中介界面来提供诸如 LoadLib()
, LoadSym()
等功能,它调用aproppriate本机API。换句话说,当编译Windows LoadLib()
将使用 LoadLibraryA()
,而在Linux上它将使用 dlopen()
。
这将让您从主代码中隐藏代码的这个丑陋的部分,使其保持更可读。
I have an application which I have managed to keep reasonably cross-platform between windows and Linux. Cmake and Boost have been helpful in this endeavor.
The time has come to link to a .dll which has been written for windows. If I can put off the conversion of the dynamically linked library it would be a good thing. Other windows applications connect up to this library like this:
HINSTANCE dll;
dll = LoadLibraryA(filename);
//...
libFuncPtr = (libFuncPtr)GetProcAddress(dll, "libFunc");
I'd like to know if there are generic analogs to these functions or is it time to start dropping in my system specific preprocessor directives? The Current Priority for Developemt is Windows, It's understood there will have to be a Linux port of the library for the Linux build to work, but I'd like to keep the calling code as generic as possible.
Start dropping system specific preprocessor directives.
You could write an intermediary interface to provide functions like LoadLib()
, LoadSym()
, etc, that calls the aproppriate native API. In other words, when compiling for Windows LoadLib()
will use LoadLibraryA()
and on Linux it will use dlopen()
.
This will let you hide this ugly part of the code from your main code so it stays more readable.
这篇关于跨平台动态链接(Windows到linux)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!