Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
355 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?

See Question&Answers more detail:os

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

1 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...