如何使用 MSVC 从 Windows 中的命令行构建 DLL [英] How to build a DLL from the command line in Windows using MSVC

查看:22
本文介绍了如何使用 MSVC 从 Windows 中的命令行构建 DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用 C 大约 20 年了,但我从未构建过 DLL;我一直更喜欢静态链接.

I've been doing C for about 20 years but I've never built a DLL; I've always prefered to statically link.

我使用命令行 - cl.exe 等 - 和 gnumake 生成文件来构建我的 Windows 应用程序.

I use the command line - cl.exe, etc - and gnumake makefiles, to build my Windows applications.

我现在想构建一个 DLL,但我很困惑.

I now want to build a DLL and I'm confused.

最终,我会得到一个 .lib 和一个 .dll..lib 包含存根代码,它在运行时加载 DLL 并使用其中的代码.

Ultimately, I will end up with both a .lib and a .dll. The .lib contains stub code which at run time loads the DLL and uses the code therein.

我一直在查看 lib 和 link 的命令行,但我不清楚应该做什么来产生这个输出.

I've been looking at the command lines for lib and link and it is not apparent to me exactly what is supposed to be done, to produce this output.

所以我有一些问题;

cl 是否需要任何额外的参数来表明它正在为 DLL 编译?(我知道 DLL 导出的原型需要 __declspec(dllexport)).

Does cl need any additional arguments, to indicate it is compiling for a DLL? (I know the DLL exported prototypes need __declspec(dllexport)).

我知道链接需要/dll 作为参数.

I know link needs /dll as an argument.

我会运行 lib 链接,分别生成 .lib 和 .dll,还是链接生成两者?

Will I run lib and link, to produce the .lib and .dll respectively, or will link produce both?

我还需要知道什么?

推荐答案

事实证明它会自动发生.

Turns out it happens automatically.

如果您有导出函数(例如/export、__declspec(dllexport) 等),链接器将自动生成 .lib 文件(您当然需要在链接器命令行上使用/dll).

If you have exported functions (e.g. /export, __declspec(dllexport), etc) the linker will automatically generate the .lib file (you do of course need /dll on the linker command line).

这篇关于如何使用 MSVC 从 Windows 中的命令行构建 DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆