Using both .so and .dll on Windows

左心房为你撑大大i 提交于 2019-11-28 01:40:37

问题


I am writing a program in windows in C++ in which users will be able to compile extensions in the form of dynamic-link libraries (windows), or shared object files (linux).

On windows, you use the LoadLibrary function to load a dll. Is it possible to do the same for .so files on windows and vice versa, load .dlls on linux?


回答1:


The short answer is "No"

That is not about loading but about internal format of dynamic library like expected entry points. Each operating system support it's own format. Hence it won't work.

  • DLL is a PE executable (as are exe on windows)
  • .so is usually an ELF format (like most modern executables on Linux/Unix).

However on Linux there is some support for PE executable through Wine, and Wine program can use DLL. But that's probably not what you are looking for.

On Windows there is also some support of ELF format through cygwin, and there is also some compilers that can load coff format (the one used on Unix before ELF). I used DJGPP for this a long time ago.




回答2:


DLLs and SOs are fundamentally different formats, so in short, no, you can't load a DLL on Linux or an SO on Windows.




回答3:


AFAIK, they way that Windows and Linux handle shared function calls are very different (how variables are stored on the stack, for one), so the .so files will not work on Win32 platform, and .dlls will not work on Linux.



来源:https://stackoverflow.com/questions/3233766/using-both-so-and-dll-on-windows

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!