Include .def definition file information for the linker into a .d source file

2021-11-24 Thread BoQsc via Digitalmars-d-learn
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`)





Re: Include .def definition file information for the linker into a .d source file

2021-11-24 Thread Adam D Ruppe via Digitalmars-d-learn

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


Re: Include .def definition file information for the linker into a .d source file

2021-11-24 Thread Adam D Ruppe via Digitalmars-d-learn
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...


Re: Include .def definition file information for the linker into a .d source file

2021-11-24 Thread BoQsc via Digitalmars-d-learn
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)`
```


Re: Include .def definition file information for the linker into a .d source file

2021-11-24 Thread Adam D Ruppe via Digitalmars-d-learn

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.


Re: Include .def definition file information for the linker into a .d source file

2021-11-24 Thread BoQsc via Digitalmars-d-learn
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.


Re: Include .def definition file information for the linker into a .d source file

2021-11-24 Thread BoQsc via Digitalmars-d-learn

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)
```


Re: Include .def definition file information for the linker into a .d source file

2021-11-24 Thread BoQsc via Digitalmars-d-learn
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.


Re: Include .def definition file information for the linker into a .d source file

2021-11-24 Thread Imperatorn via Digitalmars-d-learn

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?


Re: Include .def definition file information for the linker into a .d source file

2021-11-24 Thread BoQsc via Digitalmars-d-learn

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.


Re: Include .def definition file information for the linker into a .d source file

2021-11-25 Thread Imperatorn via Digitalmars-d-learn

On Wednesday, 24 November 2021 at 17:06:21 UTC, BoQsc wrote:
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`)


What most ppl do in that case is to just provide a script, for 
example build.cmd that just does what it needs. The user just 
clicks the script and it does everything for them.


Re: Include .def definition file information for the linker into a .d source file

2021-11-25 Thread zjh via Digitalmars-d-learn

On Thursday, 25 November 2021 at 06:56:38 UTC, BoQsc wrote:


In other words: as simple as possible to use.


`dmd -i`,no need `one big file`.



Re: Include .def definition file information for the linker into a .d source file

2021-11-25 Thread Stanislav Blinov via Digitalmars-d-learn

On Thursday, 25 November 2021 at 09:00:52 UTC, Imperatorn wrote:

What most ppl do in that case is to just provide a script, for 
example build.cmd that just does what it needs. The user just 
clicks the script and it does everything for them.


"How can I make it so that I don't need an extra file written in 
another language?"

"Just add yet another file written in yet another language".

Nice going there :)

Build scripts never have been scalable. A good language shall 
only require a compiler and source file(s). No extra voodoo 
mumbojumbo. This is why we have all those pragmas and the -i 
switch.


Re: Include .def definition file information for the linker into a .d source file

2021-11-25 Thread Imperatorn via Digitalmars-d-learn
On Thursday, 25 November 2021 at 09:47:50 UTC, Stanislav Blinov 
wrote:

On Thursday, 25 November 2021 at 09:00:52 UTC, Imperatorn wrote:

What most ppl do in that case is to just provide a script, for 
example build.cmd that just does what it needs. The user just 
clicks the script and it does everything for them.


"How can I make it so that I don't need an extra file written 
in another language?"

"Just add yet another file written in yet another language".

Nice going there :)

Build scripts never have been scalable. A good language shall 
only require a compiler and source file(s). No extra voodoo 
mumbojumbo. This is why we have all those pragmas and the -i 
switch.


Scalable or not it's a pretty common pattern. The build script is 
modular.


I wouldn't call the linker "mumbojumbo". Voodo maybe, yes.