On Tuesday, 3 August 2021 at 21:40:09 UTC, james.p.leblanc wrote:
I am getting linker errors with this stripped-down example:

-------------------------------------------
**my_main.d:**

import std.stdio;
import std.complex;
import my_module;


    void main(){
          my_TYPE xxx;
          writeln(xxx);
    }

-------------------------------------------
**my_module.d:**

module my_module;

import std.complex;

alias my_TYPE = Complex!double; *// this causes link error: "undefined reference"*

/* alias my_TYPE = double; */      *// this works fine*

------------------------------------------

Why does the linker fail when I alias to the Complex!double ...
but would work fine when alias to the double ??

Any help to understand what is greatly appreciated.
James

The alias to Complex!double is a template instantiation. A template instantiation creates a symbol that needs to be linked. So you need to compile my_module.d along with my_main.d.

```
dmd my_main.d my_module.d
```

Or alternatively:

```
dmd -i my_main.d
```

double is a built-in type, so that alias doesn't create any symbols that need linking.

An alias in and of itself is a compile-time-only construct, but the symbols you assign it might require linking something.

Reply via email to