Building DLL

S

Simon Cheng

Hi,

I have a simple question of building a DLL as follows: (VC2003)

my_dll.h
======
#ifndef SHELL_DLL_API
#define SHELL_DLL_API extern "C" __declspec(dllimport)
#endif
SHELL_DLL_API VOID DoSomething();

my_dll.cpp
========
#include <windows.h>
#define MY_DLL_API extern "C" __declspec(dllexport)
#include "my_dll.h"
BOOL WINAPI DllMain(HINSTANCE, DWORD, LPVOID) { return TRUE; }
VOID DoSomething() { return; }

Then I use the following cmdline:

cl /nologo /Od /Zi /DLL my_dll.cpp

And get the following result:

Shell_Dll.cpp
Creating library Shell_Dll.lib and object Shell_Dll.exp
LINK : fatal error LNK1561: entry point must be defined <----------

Supposedly the linker would use _DllMainCRTStartup as the default DLL entry?
Also, if I explicit specify the /ENTRY option, the linker doesn't recognize
it.
What am I missing?

Thanks,
Simon
 
J

Jeff Partch [MVP]

Simon Cheng said:
Hi,

I have a simple question of building a DLL as follows: (VC2003)

my_dll.h
======
#ifndef SHELL_DLL_API
#define SHELL_DLL_API extern "C" __declspec(dllimport)
#endif
SHELL_DLL_API VOID DoSomething();

my_dll.cpp
========
#include <windows.h>
#define MY_DLL_API extern "C" __declspec(dllexport)
#include "my_dll.h"
BOOL WINAPI DllMain(HINSTANCE, DWORD, LPVOID) { return TRUE; }
VOID DoSomething() { return; }

Then I use the following cmdline:

cl /nologo /Od /Zi /DLL my_dll.cpp

And get the following result:

Shell_Dll.cpp
Creating library Shell_Dll.lib and object Shell_Dll.exp
LINK : fatal error LNK1561: entry point must be defined <----------

Supposedly the linker would use _DllMainCRTStartup as the default DLL entry?
Also, if I explicit specify the /ENTRY option, the linker doesn't recognize
it.
What am I missing?

No promises, but try...

cl /nologo /Od /Zi my_dll.cpp /link /DLL
 
S

Simon Cheng

Thanks, the /link option is the missing part. From MSDN:

/link linkeroptions
where:
linkeroptions
The linker option or options to be passed to the linker.
Remarks
This option passes one or more linker options to the linker. The /link
option and its linker options must appear after any file names and CL
options. A space is required between /link and linkeroptions. ...

Though the new cmdline succeeds without errors, however, there is no DLL
file produced. Explicitly specifying /OUT:my_dll linker option at the end
does produce my_dll.dll. Supposedly the linker should infer from my_dll.cpp?

Thanks,
Simon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top