Jump to page: 1 2
Thread overview
Include .def definition file information for the linker into a .d source file
Nov 24, 2021
BoQsc
Nov 24, 2021
Adam D Ruppe
Nov 24, 2021
Adam D Ruppe
Nov 24, 2021
BoQsc
Nov 24, 2021
Adam D Ruppe
Nov 24, 2021
BoQsc
Nov 24, 2021
BoQsc
Nov 24, 2021
Imperatorn
Nov 25, 2021
BoQsc
Nov 25, 2021
zjh
Nov 24, 2021
BoQsc
Nov 25, 2021
Imperatorn
Nov 25, 2021
Stanislav Blinov
Nov 25, 2021
Imperatorn
November 24, 2021

I'm not sure if I have sucessfully achieved something like this before or is it even possible right now, but there is a sample file that comes with DMD compiler: D\dmd2\samples\d\winsamp.d

The problem: winsamp.d have to be compiled with .def file.

/+ Compile with:
 +  dmd winsamp winsamp.def
 + or:
 +  dmd winsamp -L-Subsystem:Windows
 +
 + 64 bit version:
 +  dmd -m64 winsamp -L-Subsystem:Windows user32.lib
 +/

This is how the .def file looks like
(D\dmd2\samples\d\winsamp.def):

EXETYPE NT
SUBSYSTEM WINDOWS

The question: Is there a way to include the .def file instructions inside .d file, so that there won't be a need for additional .def file when compiling. (dmd winsamp)

November 24, 2021
On Wednesday, 24 November 2021 at 17:06:21 UTC, BoQsc wrote:
> **The question:** Is there a way to include the `.def` file instructions inside `.d` file, so that there won't be a need for additional `.def` file when compiling. (`dmd winsamp`)

https://dlang.org/spec/pragma.html#linkerDirective
November 24, 2021
On Wednesday, 24 November 2021 at 17:14:42 UTC, Adam D Ruppe wrote:
> https://dlang.org/spec/pragma.html#linkerDirective

example from my stuff:

import arsd.minigui;

pragma(linkerDirective, "/subsystem:windows");
pragma(linkerDirective, "/entry:mainCRTStartup");



that works with dmd -m32mscoff. need a wmainCRTStartup for ldc, no entry at all for dmd -m32.

Maybe I should make this a tempalte in my library.......
November 24, 2021

On Wednesday, 24 November 2021 at 17:14:42 UTC, Adam D Ruppe wrote:

>

On Wednesday, 24 November 2021 at 17:06:21 UTC, BoQsc wrote:

>

The question: Is there a way to include the .def file instructions inside .d file, so that there won't be a need for additional .def file when compiling. (dmd winsamp)

https://dlang.org/spec/pragma.html#linkerDirective

The many times I tried this pragma, it did not even get recognised as pragma at all.
Essentialy it did not work. Mind giving a demonstration of this pragma?

dmd winsamp.d
winsamp.d(13): Error: unrecognized `pragma(linkerDirective)`
November 24, 2021
On Wednesday, 24 November 2021 at 17:23:07 UTC, BoQsc wrote:
> The many times I tried this pragma, it did not even get recognised as pragma at all.

You need to use `dmd -m32mscoff` or `dmd -m64`. Plain `dmd` won't work.

If -m32mscoff and -m64 still don't work, what's your dmd version? It was added in 2.083.0, November 2018.
November 24, 2021

On Wednesday, 24 November 2021 at 17:29:09 UTC, Adam D Ruppe wrote:

>

On Wednesday, 24 November 2021 at 17:23:07 UTC, BoQsc wrote:

>

The many times I tried this pragma, it did not even get recognised as pragma at all.

You need to use dmd -m32mscoff or dmd -m64. Plain dmd won't work.

If -m32mscoff and -m64 still don't work, what's your dmd version? It was added in 2.083.0, November 2018.

Thanks, seems to work now.

I had to add these two pragmas to the winsamp.d

pragma(linkerDirective, "/subsystem:windows");
pragma(lib, "user32.lib");

And as you mentioned give additional-m32mscoff flag to the compiler.

dmd winsamp.d -m32mscoff

The obvious problem now is: How can you compile without specifying the flags. With plain dmd.

November 24, 2021

On Wednesday, 24 November 2021 at 17:38:42 UTC, BoQsc wrote:

>

[...]
The obvious problem now is: How can you compile without specifying the flags. With plain dmd.

It probably has to do something with the default target of dmd (-m32) generating OMF object file.
https://dlang.org/dmd-windows.html#switch-m32

-m32mscoff and -m64 both generate MS-COFF Object file instead of OMF object file.


The below error is caused when the compilation target is OMF object file instead of MS-COFF Object file.

winsamp.d(11): Error: unrecognized pragma(linkerDirective)
November 24, 2021

Since the linkerDirective pragma is not supported for OMF object file.

>

Linker directives are only supported for MS-COFF output.
https://dlang.org/spec/pragma.html#linkerDirective

I doubt that this thread is completely resolved.

November 24, 2021

On Wednesday, 24 November 2021 at 17:38:42 UTC, BoQsc wrote:

>

On Wednesday, 24 November 2021 at 17:29:09 UTC, Adam D Ruppe wrote:

>

On Wednesday, 24 November 2021 at 17:23:07 UTC, BoQsc wrote:

>

The many times I tried this pragma, it did not even get recognised as pragma at all.

You need to use dmd -m32mscoff or dmd -m64. Plain dmd won't work.

If -m32mscoff and -m64 still don't work, what's your dmd version? It was added in 2.083.0, November 2018.

Thanks, seems to work now.

I had to add these two pragmas to the winsamp.d

pragma(linkerDirective, "/subsystem:windows");
pragma(lib, "user32.lib");

And as you mentioned give additional-m32mscoff flag to the compiler.

dmd winsamp.d -m32mscoff

The obvious problem now is: How can you compile without specifying the flags. With plain dmd.

Just a quick question before going deeper. Why do you not want to supply the definition file?

November 25, 2021

On Wednesday, 24 November 2021 at 20:29:36 UTC, Imperatorn wrote:

>

On Wednesday, 24 November 2021 at 17:38:42 UTC, BoQsc wrote:

>

On Wednesday, 24 November 2021 at 17:29:09 UTC, Adam D Ruppe wrote:

>

On Wednesday, 24 November 2021 at 17:23:07 UTC, BoQsc wrote:

>

The many times I tried this pragma, it did not even get recognised as pragma at all.

You need to use dmd -m32mscoff or dmd -m64. Plain dmd won't work.

If -m32mscoff and -m64 still don't work, what's your dmd version? It was added in 2.083.0, November 2018.

Thanks, seems to work now.

I had to add these two pragmas to the winsamp.d

pragma(linkerDirective, "/subsystem:windows");
pragma(lib, "user32.lib");

And as you mentioned give additional-m32mscoff flag to the compiler.

dmd winsamp.d -m32mscoff

The obvious problem now is: How can you compile without specifying the flags. With plain dmd.

Just a quick question before going deeper. Why do you not want to supply the definition file?

To have a single standalone .d script file, that's the end goal.
I want to have everything in one .d source file and run it without specifying additional files or flags.
In other words: as simple as possible to use.

« First   ‹ Prev
1 2