在 Visual Studio 2010 C++ 中使用 MinGW 构建 dll项目

发布于 2024-09-27 10:42:01 字数 392 浏览 0 评论 0原文

我已经构建了一个 dll,现在我想在 Microsoft Visual Studio 项目中使用这个 dll。

g++ -O0 -Wall -c -fmessage-length=0 -osrc\MyLib.o ..\src\MyLib.cpp
g++ -shared -Wl,--out-implib=MyLib.lib -Wl,--output-def=MyLib.def -oMyLib.dll src\MyLib.o -lwsock32

当我在“gcc 项目”中使用它时,该 dll 工作正常。

我尝试了不同的方法来创建“.lib”和“.def”文件,并尝试按照不同的教程在 VS 中导入这些库。但是 VS 找不到 dll 中声明的方法...

我很感谢您的帮助。

I have build a dll and now I want to use this dll in a Microsoft Visual Studio project.

g++ -O0 -Wall -c -fmessage-length=0 -osrc\MyLib.o ..\src\MyLib.cpp
g++ -shared -Wl,--out-implib=MyLib.lib -Wl,--output-def=MyLib.def -oMyLib.dll src\MyLib.o -lwsock32

The dll works fine when I use it in a "gcc project".

I have tried different methodes to create the ".lib" and ".def" files and tried to import these libs in VS by following different tutorials. But VS does not find the methodes declared in the dll...

I'm thankfull for any help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

下雨或天晴 2024-10-04 10:42:01

你听说过名字修改吗?除非从 DLL 导出的函数被标记为 extern“C”,否则它们的名称将以特定于编译器的方式被破坏。于是问题就来了。

Have you heard about name mangling? Unless the functions exported from DLL are marked as extern "C" their names are going to be mangled in a compiler-specific way. Thus the problem.

冷弦 2024-10-04 10:42:01

如果您希望您的 dll 与其他编译器一起使用,您有以下选项:

  1. 仅公开“C”接口(使用
    extern "C") - 没有类或任何东西
    C++ 特定的。
  2. 制作一个COM dll。
  3. 制作如下类似 COM 的模型
    相同的限制。

If you want your dll to be used with another compiler you have the following options:

  1. Expose only "C" interface (with
    extern "C") - no classes or anyting
    C++ specific.
  2. Make a COM dll.
  3. Make your on COM-like model that follows
    the same constraints.
陌伤ぢ 2024-10-04 10:42:01

为了他人的利益。看看
二进制兼容的 C++ 接口
从上面可以清楚地看出,没有办法直接将用 MinGW 构建的 C++ DLL 与 MS Visual Studio 接口。这种接口只能通过基于 C 的接口才能干净地“工作”。

For the benefit of others. Have a look at
Binary Compatible C++ Interfaces.
Its clear from the above that there is no way direct to interface C++ DLL built with MinGW with MS Visual Studio. This interfacing "works" cleanly only via C based interface.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文