Comment #1 by dlang-bugzilla — 2014-03-23T03:13:43Z
For the record, Delphi does away with import libraries completely and solves the DLL problem in the language. E.g.:
function MessageBoxA(hWnd: HWND; lpText, lpCaption: PChar; uType: UINT): Integer; stdcall; external 'user32.dll';
So in theory D could have an extern(dll, "user32.dll") attribute.
Comment #2 by andrej.mitrovich — 2014-03-23T03:24:26Z
(In reply to comment #1)
> For the record, Delphi does away with import libraries completely and solves
> the DLL problem in the language. E.g.:
>
> function MessageBoxA(hWnd: HWND; lpText, lpCaption: PChar; uType: UINT):
> Integer; stdcall; external 'user32.dll';
>
> So in theory D could have an extern(dll, "user32.dll") attribute.
It would be a little complicated with platform-independent shared libraries. For example:
-----
version (Windows) extern(dll, "user32.dll")
extern(C) void foo();
void main()
{
foo(); // would fail on Posix since the entire block becomes invisible
}
-----
We currently cannot do the following:
-----
version (Windows)
extern(C++):
else
extern(C):
void foo();
void main()
{
}
-----
Unless this is fixed extern(dll, "user32.dll") would only be usable for Windows DLLs, or you'd likely have to duplicate code / resort to string mixins and other unreadable hacks..
Comment #3 by andrej.mitrovich — 2014-03-23T03:42:05Z
(In reply to comment #2)
> -----
> version (Windows) extern(dll, "user32.dll")
> extern(C) void foo();
>
> void main()
> {
> foo(); // would fail on Posix since the entire block becomes invisible
> }
> -----
That wasn't a proper argument since the dll string name can be generated at compile-time.
To provide a slightly better argument, let's say you have "foo.dll", "foo_deb.dll" on Windows, and "foo.a", "foo_deb.a" on Posix. You'd end up writing:
-----
version (Windows)
{
debug
enum dll_name = "foo.dll";
else
enum dll_name = "foo_deb";
}
else
version (Posix)
{
debug
enum dll_name = "foo.a";
else
enum dll_name = "foo_deb.a";
}
extern(dll, dll_name)
void foo();
-----
But then there might be issues where the shared library is named differently based on the OS itself, some platform-specific naming conventions, x86 vs x64, etc.. It would be simpler if you could just pass the shared library directly to DMD.
Comment #4 by dlang-bugzilla — 2014-03-23T03:44:20Z
It would be simpler if the project is already using some non-trivial build system. Allowing specifying it in the source code has the same advantage as pragma(lib): it allows using only rdmd to build the program.
I think there is merit in both.
Comment #5 by andrej.mitrovich — 2014-03-23T03:47:16Z
(In reply to comment #4)
> It would be simpler if the project is already using some non-trivial build
> system. Allowing specifying it in the source code has the same advantage as
> pragma(lib): it allows using only rdmd to build the program.
Well, yeah, but you still can't provide strings at compile time via a compiler switch, maybe only through string imports.
(In reply to comment #4)
> I think there is merit in both.
Yes, agreed.
Comment #6 by robert.schadek — 2024-12-13T18:18:40Z