www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Linker error

reply Chris <wendlec tcd.ie> writes:
I get the error below with code like this:

auto res = ['1', '2'].map!(a => a.to!string);

dmd 2.071.0

What's wrong here? I import std.algorithm, std.range, std.array, 
std.conv in the module.

(.data._D65TypeInfo_xC3std5range10interfaces18__T10InputRangeTiZ10Input
ange6__initZ+0x10): undefined reference to
`_D64TypeInfo_C3std5range10interfaces18__T10InputRangeTiZ10InputRange6__initZ'
collect2: error: ld returned 1 exit status
Jun 10 2016
next sibling parent reply ketmar <ketmar ketmar.no-ip.org> writes:
On Friday, 10 June 2016 at 12:04:50 UTC, Chris wrote:
 I get the error below with code like this:

 auto res = ['1', '2'].map!(a => a.to!string);

 dmd 2.071.0

 What's wrong here? I import std.algorithm, std.range, 
 std.array, std.conv in the module.

 (.data._D65TypeInfo_xC3std5range10interfaces18__T10InputRangeTiZ10Input
ange6__initZ+0x10): undefined reference to
`_D64TypeInfo_C3std5range10interfaces18__T10InputRangeTiZ10InputRange6__initZ'
 collect2: error: ld returned 1 exit status
post the whole code and command line, please. it looks like you doing separate compilation, and forgot to put something to command line, or there is some conflict between installed compiler versions (for example, dmd and ldc, and one somehow is trying to use libphobos from another).
Jun 10 2016
parent reply Chris <wendlec tcd.ie> writes:
On Friday, 10 June 2016 at 12:12:17 UTC, ketmar wrote:
 On Friday, 10 June 2016 at 12:04:50 UTC, Chris wrote:
 I get the error below with code like this:

 auto res = ['1', '2'].map!(a => a.to!string);

 dmd 2.071.0

 What's wrong here? I import std.algorithm, std.range, 
 std.array, std.conv in the module.

 (.data._D65TypeInfo_xC3std5range10interfaces18__T10InputRangeTiZ10Input
ange6__initZ+0x10): undefined reference to
`_D64TypeInfo_C3std5range10interfaces18__T10InputRangeTiZ10InputRange6__initZ'
 collect2: error: ld returned 1 exit status
post the whole code and command line, please. it looks like you doing separate compilation, and forgot to put something to command line, or there is some conflict between installed compiler versions (for example, dmd and ldc, and one somehow is trying to use libphobos from another).
The whole code would be too much. This, however compiles and links perfectly well: ` import std.algorithm; import std.conv : to; void main() { auto res = [1, 2, 3].map!(a => a.to!string); } ` I use dub and `dvm use 2.071.0`. The code compiled perfectly well until I used `map!` I have no clue what causes it. I even used `dub clean`
Jun 10 2016
parent reply ketmar <ketmar ketmar.no-ip.org> writes:
On Friday, 10 June 2016 at 12:52:05 UTC, Chris wrote:
 I use dub and `dvm use 2.071.0`.
hm. sorry, i can't help you with this. straight "dmd test.d" is ok, so it's probably something with dub/dvm interaction...
Jun 10 2016
parent reply Chris <wendlec tcd.ie> writes:
On Friday, 10 June 2016 at 13:00:23 UTC, ketmar wrote:
 On Friday, 10 June 2016 at 12:52:05 UTC, Chris wrote:
 I use dub and `dvm use 2.071.0`.
hm. sorry, i can't help you with this. straight "dmd test.d" is ok, so it's probably something with dub/dvm interaction...
It doesn't compile with `dmd file1.d file2.d` either. I'll have to look into this. Weird.
Jun 10 2016
parent ketmar <ketmar ketmar.no-ip.org> writes:
On Friday, 10 June 2016 at 13:04:32 UTC, Chris wrote:
 It doesn't compile with

 `dmd file1.d file2.d`

 either. I'll have to look into this. Weird.
looks like a clear sign of dmd versions conflict. most of the time things like that caused by some leftover from previous dmd — like old libphobos.a lying somewhere in link path, or alike. try to get link command from "dmd -v", and supply it with explicit path to correct libphobos to check if there is really something interferring.
Jun 10 2016
prev sibling parent reply Steven Schveighoffer <schveiguy yahoo.com> writes:
On 6/10/16 8:04 AM, Chris wrote:
 I get the error below with code like this:

 auto res = ['1', '2'].map!(a => a.to!string);

 dmd 2.071.0

 What's wrong here? I import std.algorithm, std.range, std.array,
 std.conv in the module.

 (.data._D65TypeInfo_xC3std5range10interfaces18__T10InputRangeTiZ10InputRange6__initZ+0x10):
 undefined reference to
 `_D64TypeInfo_C3std5range10interfaces18__T10InputRangeTiZ10InputRange6__initZ'

 collect2: error: ld returned 1 exit status
This linker error is saying it can't find a required typeinfo initializer for std.range.interfaces.InputRange (of some type, not an expert in demangling D symbols). Generally this happens when you compile against a third-party library file but don't link to it (I think that type of symbol is stored in the module info). Your posted code has nothing to do with this, so I'm not sure this is the exact line you are having trouble with. Your posted map line should not be invoking this error at all. Have you tried Vladimir's DustMite tool? It can automatically whittle down your code into a minimal test case. https://github.com/CyberShadow/DustMite/wiki -Steve
Jun 10 2016
parent Chris <wendlec tcd.ie> writes:
On Friday, 10 June 2016 at 13:17:32 UTC, Steven Schveighoffer 
wrote:
 On 6/10/16 8:04 AM, Chris wrote:
 I get the error below with code like this:

 auto res = ['1', '2'].map!(a => a.to!string);

 dmd 2.071.0

 What's wrong here? I import std.algorithm, std.range, 
 std.array,
 std.conv in the module.

 (.data._D65TypeInfo_xC3std5range10interfaces18__T10InputRangeTiZ10InputRange6__initZ+0x10):
 undefined reference to
 `_D64TypeInfo_C3std5range10interfaces18__T10InputRangeTiZ10InputRange6__initZ'

 collect2: error: ld returned 1 exit status
This linker error is saying it can't find a required typeinfo initializer for std.range.interfaces.InputRange (of some type, not an expert in demangling D symbols). Generally this happens when you compile against a third-party library file but don't link to it (I think that type of symbol is stored in the module info). Your posted code has nothing to do with this, so I'm not sure this is the exact line you are having trouble with. Your posted map line should not be invoking this error at all. Have you tried Vladimir's DustMite tool? It can automatically whittle down your code into a minimal test case. https://github.com/CyberShadow/DustMite/wiki -Steve
I've got it now. I remembered that it is to do with passing -allinst to the compiler. You're right, it's not `map!` as such. It's the template instantiation. However, the problem only appeared when I started to use `map!`
Jun 10 2016