Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
201 views
in Technique[技术] by (71.8m points)

c - How to build a DLL from the command line in Windows using MSVC

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?

question from:https://stackoverflow.com/questions/1130479/how-to-build-a-dll-from-the-command-line-in-windows-using-msvc

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

On the command line use:

cl.exe /LD <files-to-compile>

or, if you prefer the more verbose & explicit version:

cl.exe /D_USRDLL /D_WINDLL <files-to-compile> <files-to-link> /link /DLL /OUT:<desired-dll-name>.dll

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...