Compiling a DLL with DMC
Mike Parker via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Jul 29 22:33:31 PDT 2015
I'm trying to compile a DLL using DMC for use in a sample DMD
program, but the link stage keeps failing and I can't figure out
why. The C source:
```
#include <stdio.h>
#ifdef __DMC__
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
BOOL APIENTRY DllMain(HANDLE hModule, DWORD reason, LPVOID
lpReserved) {
switch (reason)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
#endif
int some_c_function(int a) {
printf("Hello, D! From C! %d", a);
return a + 20;
}
```
The definition file:
EXPORTS
DllMain
some_c_function
The command line:
dmc -mn -WD dll-testing.cpp kernel32.lib clib.def
The errors:
OPTLINK : Error 180: No Match Found for Export/ENTRY - : DllMain
OPTLINK : Error 180: No Match Found for Export/ENTRY - :
some_c_function
OPTLINK : Warning 148: USE16/USE32 Mismatch : DGROUP
C:\dm\bin\..\lib\SNN.lib(dllstart)
Error 83: Illegal frame on start address
OPTLINK : Warning 174: 32-bit Segments Inappropriate for 16-bit
Segmented output
OPTLINK : Error 81: Cannot EXPORT : DllMain
OPTLINK : Error 81: Cannot EXPORT : some_c_function
clib.obj(clib)
Error 35: Cannot Reach TARGET from FRAME at Relative 00024H from
Segment _TEXT
FRAME = Frame of Group FLAT 0000
TARGET = External Symbol _printf 001ACH
FIXUPP Type = 32-bit Conditional JMP
I've tried ditching the def file and using __declspec(dllexport)
directly on the functions and got the same result. Does anyone
know how to compile a DLL with DMC?
More information about the Digitalmars-d-learn
mailing list