What is this undefined reference with -betterC about?

jfondren julian.fondren at gmail.com
Wed Jun 16 16:52:26 UTC 2021


On Wednesday, 16 June 2021 at 16:27:13 UTC, Dennis wrote:
> On Wednesday, 16 June 2021 at 14:38:10 UTC, jfondren wrote:
>> What do I change to
>> 1. a script like this that uses hostname
>> 2. the hostname module
>>
>> so that both can be built with -betterC when and only when
>> the script is using -betterC?
>
> That's currently the situation: you can only build when both 
> are betterC or else you get a linker error. It has to be a 
> linker error, dmd cannot know at the time of compiling project 
> A how project B is going to be compiled and vice versa.

It's dub that's calling dmd though. Cargo handles this situation 
with
features: https://doc.rust-lang.org/cargo/reference/features.html 
Where
this case would look something like

```
[dependencies]
hostname = { version = "0.1.1", features = ["betterC"] }
```

in the script's dub config that uses hostname.

I feel like I've seen similar configurations in dub configs, but 
I see
nothing about this in the documentation.

> It noticed your code looks like this:
> ```D
> version(D_BetterC) {
>     char* hostnamez;
> } else {
>     immutable char* hostnamez;
> }
> ```
>
> The different types result in different mangles, causing the 
> linking errors. Why not simply give them the same type?

the pragma(crt_constructor) function can't initialize immutables:
https://forum.dlang.org/post/wvjfygxfvmoaortmndcv@forum.dlang.org


More information about the Digitalmars-d-learn mailing list