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

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

问题描述

我已经做下约20年,但我从来没有建立了一个DLL;我一直prefered静态链接。

我用命令行 - cl.exe时,等等 - 和gnumake的生成文件,建立我的Windows应用程序

我现在要建立一个DLL,我很困惑。

最后,我将结束与既有的.lib和一个.dll。该的.lib包含存根code这在运行时加载DLL,并使用code在其中。

我一直在寻找的lib和链接命令行,这究竟是看不出来对我来说什么是应该做的,产生这种输出。

所以我有一些问题;

CL是否需要任何额外的参数,以表明它正在编制一个DLL? (我知道DLL导出原型需要__declspec(dllexport)的)。

我知道链接需要/ DLL作为参数。<​​/ P>

我会跑的lib的的链接,产生的.lib和.dll分别,或将链接同时生产?

还有什么我需要知道什么?


解决方案

原来这是自动发生的。

如果您导出功能(例如/导出,_​​_declspec(dllexport)的等),连接器会自动生成的.lib文件(你当然需要链接器命令行上/ DLL)。

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

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

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

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.

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.

So I have some questions;

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

I know link needs /dll as an argument.

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

What else do I need to know?

解决方案

Turns out it happens automatically.

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来构建从命令行一个DLL在Windows的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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