By piping the linker's output to linkdef and supplying which library to scan for functions, a def file will be generated with which you can create an import library lib file using Digital Mars' implib utility.
link_output = Output of Digital Mars link. This can be from directly using link, through DMD, through executing a batch file or other type of script, or even from a file using the type command.
This is piped into linkdef using the | pipe character.
switches
-n = Do not create backup def file if the target def file exists.
-v = Verbose output.
library_name = Library name to check for functions. Do not include file name extensions.
Implib usage is available here.
import std.string;
import std.c.windows.windows;
extern(Windows) HINSTANCE ShellExecuteA(HWND, LPCTSTR,
LPCTSTR, LPCTSTR, LPCTSTR, INT);
int main(char[][] args)
{
if(args.length < 2) return 1;
ShellExecuteA(null, "open", toStringz(args[1]), null, null, SW_SHOW);
return 0;
}
Then I compile like so:
C:\d\exec>dmd code.d c:\dmd\bin\..\..\dm\bin\link.exe code,,,user32+kernel32/noi; OPTLINK (R) for Win32 Release 7.50B1 Copyright (C) Digital Mars 1989 - 2001 All Rights Reserved code.obj(code) Error 42: Symbol Undefined _ShellExecuteA@24 --- errorlevel 1
MSDN tells me ShellExecute is in shell32.dll, so run this information through linkdef on the command line:
C:\d\exec>dmd code.d | linkdef shell32 linkdef 1.0 Copyright 2005 Christopher E. Miller c:\dmd\bin\..\..\dm\bin\link.exe code,,,user32+kernel32/noi; OPTLINK (R) for Win32 Release 7.50B1 Copyright (C) Digital Mars 1989 - 2001 All Rights Reserved code.obj(code) Error 42: Symbol Undefined _ShellExecuteA@24 --- errorlevel 1 linkdef: 1 undefined symbols linkdef: File shell32.def successfully created linkdef: Use: implib shell32.lib shell32.def
Linkdef gave me a shell32.def file that I can pass to implib like so:
C:\d\exec>implib shell32.lib shell32.def Digital Mars Import Library Manager Version 7.6B1n Copyright (C) Digital Mars 2000. All Rights Reserved. Output is a Windows NT import library. Digital Mars Import Library Creator complete.
Now compile it:
C:\d\exec>dmd code.d shell32.lib c:\dmd\bin\..\..\dm\bin\link.exe code,,,shell32.lib+user32+kernel32/noi;
All set; use the program.
C:\d\exec>code www.dprogramming.com
C:\d\supercool>dmd cool.d yours.lib their.lib | linkdef some ... Unable to find 13 undefined symbols ... C:\d\supercool>implib some.lib some.def ... C:\d\supercool>dmd cool.d yours.lib their.lib some.lib | linkdef next ... Unable to find 2 undefined symbols ... C:\d\supercool>implib next.lib next.def ... C:\d\supercool>dmd cool.d yours.lib their.lib some.lib next.lib | linkdef last ... C:\d\supercool>implib last.lib last.def ... C:\d\supercool>dmd cool.d yours.lib their.lib some.lib next.lib last.lib ...Note: example trimmed for brevity.