douzi8127
2017-10-09 12:45
浏览 324

Golang,在Linux中加载Windows DLL

Our vendor provides DLL, which works on Windows. Is this possible to load custom xxx.dll file and use its functions in Linux using Go?

Like this: https://github.com/golang/go/wiki/WindowsDLLs

图片转代码服务由CSDN问答提供 功能建议

我们的供应商提供了可在Windows上运行的DLL。

是否可以这样加载自定义的 xxx.dll 文件并在 Linux 中使用其功能? =“ https://github.com/golang/go/wiki/WindowsDLLs” rel =“ nofollow noreferrer”> https://github.com/golang/go/wiki/WindowsDLLs

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dtbam62840 2017-10-09 14:36
    已采纳

    The short answer is "no": when you "load" a dynamic-linked library, it's not only actually loaded (as in read from the file) but linked into the address space of your running program — by the special means provided by the OS (on Linux-based systems, at least on x86/amd64 platforms that's an external process; on Windows, it's an in-kernel facility, AFAIK). In other words, loading a dynamic-linked library involves quite a lot of complexity happening behind your back.

    Another complication, is whether the DLL is "self-contained" in the sense it only contains "pure" functions — which only perform computations on their input data to provide their output data, — or they call out to the operating system to perform activities such as I/O on files. The way operating systems provide ways to do these kinds of activities to the running processes are drastically different between Windows and Linux.

    The last complication I can think of is dependency of this library on others. If the library's code is written in C or C++, it quite likely depends on the C library used by the compiler which compiled the library (on Windows, it's typically that MSVCRxx.DLL thing). (A simple example is calling malloc() or printf() or something like this in a library's code.)

    All this means that most of a DLL written on Windows for Windows depends both on Windows and the C or C++ standard library associated with the compiler used to build that library.

    That's not to mention that Windows DLL uses PE (Portable Executable) format for its modules while GNU/Linux-based systems natively use the ELF format for its shared object files.

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • douyi4544 2017-10-09 14:31

    I'm afraid not because the windows DLLs do different kernel calls than Linux shared object, both has this fancy name for system library objects

    But if you need to run a windows native app on linux I would recommend give Wine a try, I doubt it works properly, and a second worthy try is dosbox, once I doubt this works too

    But there is a little hope if those DLLs are written in .net framework, you could wrap them up on a nice c# code and use mono on linux side, not sure if this enables you to import those DLLs to golang, but I don't think so either

    In the and with that amount of tricks to have everything working you will get some performance issues, just saying

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题