digitalmars.D.learn - alias using Complex!Double in module ... linker error??
- james.p.leblanc (22/22) Aug 03 2021 I am getting linker errors with this stripped-down example:
- Mike Parker (15/37) Aug 03 2021 The alias to Complex!double is a template instantiation. A
- james.p.leblanc (11/28) Aug 03 2021 Mike,
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
Aug 03 2021
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. JamesThe 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.
Aug 03 2021
On Wednesday, 4 August 2021 at 01:10:15 UTC, Mike Parker wrote:On Tuesday, 3 August 2021 at 21:40:09 UTC, james.p.leblanc wrote:Mike, Aha... that makes sense now! Thanks kindly for helping me understand what was happening with your informative reply. The fact of template instantiations and symbols had escaped me completely. I appreciate it. Best Regards, 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.
Aug 03 2021