问题描述
我正在C ++中编写一个程序,用户可以使用动态链接库(Windows)或共享对象文件(linux)的形式来编译扩展。在Windows上,您可以使用 LoadLibrary
函数加载dll。可以在Windows上对.so文件做同样的事情,反之亦然,在linux上加载.dlls?
答案是否
这不是关于加载,而是关于动态库的内部格式,如预期的入口点。每个操作系统都支持它自己的格式。因此它将无法正常工作。
- DLL是一个PE可执行文件(和Windows上一样)
- .so通常是ELF格式(像Linux / Unix上大多数现代可执行文件)。
但是在Linux上有一些支持通过Wine可执行PE,而Wine程序可以使用DLL。但是这可能不是你想要的。
在Windows上,还有一些支持ELF格式的cygwin,还有一些编译器可以加载coff格式在ELF之前在Unix上使用的)。我很久以前就使用过DJGPP。
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?
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.
这篇关于在Windows上同时使用.so和.dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!