www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Undefined reference error when array size is given

reply "tcak" <tcak gmail.com> writes:
Code is as follows:

main.d
=========================
import core.sys.posix.poll;

void main(){
	core.sys.posix.poll.pollfd[2] pollList;
}
=========================


Error:
main.d:(.text._Dmain+0x15): undefined reference to 
`_D4core3sys5posix4poll6pollfd6__initZ'


Remove "2" and it works.

main.d
==========================
import core.sys.posix.poll;

void main(){
	core.sys.posix.poll.pollfd[] pollList;
}
=========================


The error points to "__init". Struct is defined very simply.

     struct pollfd
     {
         int     fd;
         short   events;
         short   revents;
     }


I defined same struct in main file, and defined a similar array. 
There is no problem with that.

main.d
=========================
import core.sys.posix.poll;

struct pollfd2
{
     int     fd;
     short   events;
     short   revents;
}

void main(){
	core.sys.posix.poll.pollfd[] pollList;

	pollfd2[2] blah;
}
=========================

What is the reason of this error exactly?
Jan 19 2015
next sibling parent reply ketmar via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> writes:
On Mon, 19 Jan 2015 21:00:55 +0000
tcak via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:

 What is the reason of this error exactly?
"core.sys.posix.poll.d" module is not compiled into druntime. as it is in "include" path, compiler sees it and you can use `pollfd` struct. but as it's not in link library, there is no `.init` section for it. as a workaroun you can either manually add that module to dmd command line, or use `pollfd[2] pollList =3D void;` (and don't forget to manually initialise ALL pollfd fields for all array elements then).
Jan 19 2015
parent reply Steven Schveighoffer <schveiguy yahoo.com> writes:
On 1/19/15 4:16 PM, ketmar via Digitalmars-d-learn wrote:
 On Mon, 19 Jan 2015 21:00:55 +0000
 tcak via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:

 What is the reason of this error exactly?
"core.sys.posix.poll.d" module is not compiled into druntime. as it is in "include" path, compiler sees it and you can use `pollfd` struct. but as it's not in link library, there is no `.init` section for it.
I think this not the root cause. Of course poll.d should be in druntime, if applicable. What I likely think is that he is compiling on a platform where poll.d is not supported. Can you give more info on your build environment? -Steve
Jan 19 2015
next sibling parent reply ketmar via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> writes:
On Mon, 19 Jan 2015 16:27:51 -0500
Steven Schveighoffer via Digitalmars-d-learn
<digitalmars-d-learn puremagic.com> wrote:

 On 1/19/15 4:16 PM, ketmar via Digitalmars-d-learn wrote:
 On Mon, 19 Jan 2015 21:00:55 +0000
 tcak via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:

 What is the reason of this error exactly?
"core.sys.posix.poll.d" module is not compiled into druntime. as it is in "include" path, compiler sees it and you can use `pollfd` struct. but as it's not in link library, there is no `.init` section for it.
=20 I think this not the root cause. Of course poll.d should be in druntime,=
=20
 if applicable.
=20
 What I likely think is that he is compiling on a platform where poll.d=20
 is not supported.
=20
 Can you give more info on your build environment?
i tried that on my 32-bit GNU/Linux box, and the result is the same. but `poll (2)` is certainly supported here. dmd git head, as usual. ;-)
Jan 19 2015
parent reply Steven Schveighoffer <schveiguy yahoo.com> writes:
On 1/19/15 4:33 PM, ketmar via Digitalmars-d-learn wrote:
 On Mon, 19 Jan 2015 16:27:51 -0500
 Steven Schveighoffer via Digitalmars-d-learn
 <digitalmars-d-learn puremagic.com> wrote:

 On 1/19/15 4:16 PM, ketmar via Digitalmars-d-learn wrote:
 On Mon, 19 Jan 2015 21:00:55 +0000
 tcak via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:

 What is the reason of this error exactly?
"core.sys.posix.poll.d" module is not compiled into druntime. as it is in "include" path, compiler sees it and you can use `pollfd` struct. but as it's not in link library, there is no `.init` section for it.
I think this not the root cause. Of course poll.d should be in druntime, if applicable. What I likely think is that he is compiling on a platform where poll.d is not supported. Can you give more info on your build environment?
i tried that on my 32-bit GNU/Linux box, and the result is the same. but `poll (2)` is certainly supported here. dmd git head, as usual. ;-)
I figured it out, poll.d is missing from here: https://github.com/D-Programming-Language/druntime/blob/master/mak/SRCS So it's for some reason not purposely included. I think there's an expectation (I'm probably guilty of this too) that if you include a file somewhere in druntime's core subdirectory, it gets compiled in. There are actually quite a few files not included... not sure why. -Steve
Jan 19 2015
next sibling parent reply ketmar via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> writes:
On Mon, 19 Jan 2015 16:49:34 -0500
Steven Schveighoffer via Digitalmars-d-learn
<digitalmars-d-learn puremagic.com> wrote:

 I figured it out, poll.d is missing from here:
=20
 https://github.com/D-Programming-Language/druntime/blob/master/mak/SRCS
=20
 So it's for some reason not purposely included.
=20
 I think there's an expectation (I'm probably guilty of this too) that if=
=20
 you include a file somewhere in druntime's core subdirectory, it gets=20
 compiled in.
=20
 There are actually quite a few files not included... not sure why.
i believe that they are just accidentally left out. besides, if some file defines only extern functions and constants, it can be safely ommited. yet including it will not hurt too (and will add some sanity checks on build time -- like ensuring that it is syntactically correct). so i believe that this is an accidental omission that worth a PR.
Jan 19 2015
parent reply Steven Schveighoffer <schveiguy yahoo.com> writes:
On 1/19/15 4:54 PM, ketmar via Digitalmars-d-learn wrote:
 On Mon, 19 Jan 2015 16:49:34 -0500
 Steven Schveighoffer via Digitalmars-d-learn
 <digitalmars-d-learn puremagic.com> wrote:

 I figured it out, poll.d is missing from here:

 https://github.com/D-Programming-Language/druntime/blob/master/mak/SRCS

 So it's for some reason not purposely included.

 I think there's an expectation (I'm probably guilty of this too) that if
 you include a file somewhere in druntime's core subdirectory, it gets
 compiled in.

 There are actually quite a few files not included... not sure why.
i believe that they are just accidentally left out. besides, if some file defines only extern functions and constants, it can be safely ommited. yet including it will not hurt too (and will add some sanity checks on build time -- like ensuring that it is syntactically correct). so i believe that this is an accidental omission that worth a PR.
I want to make a PR, but I'm considering whether I should PR ALL the missing modules, or just this one :) I will consult the devs mailing list... BTW, I've seen linker errors happen when you don't include a module, even if there's seemingly nothing to deal with in there. To the point where I just include all modules even if I think I can omit them. -Steve
Jan 19 2015
parent ketmar via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> writes:
On Mon, 19 Jan 2015 17:05:22 -0500
Steven Schveighoffer via Digitalmars-d-learn
<digitalmars-d-learn puremagic.com> wrote:

 BTW, I've seen linker errors happen when you don't include a module,=20
 even if there's seemingly nothing to deal with in there. To the point=20
 where I just include all modules even if I think I can omit them.
this is good for all-at-once compilation, but separate compilation is a different story... it's often hard/burdensome to convince a build tool to include given module in a command line. and most non D-specific build tools are written with separate compilation model in mind.
Jan 19 2015
prev sibling parent reply Steven Schveighoffer <schveiguy yahoo.com> writes:
On 1/19/15 4:49 PM, Steven Schveighoffer wrote:

 I figured it out, poll.d is missing from here:

 https://github.com/D-Programming-Language/druntime/blob/master/mak/SRCS

 So it's for some reason not purposely included.

 I think there's an expectation (I'm probably guilty of this too) that if
 you include a file somewhere in druntime's core subdirectory, it gets
 compiled in.

 There are actually quite a few files not included... not sure why.
And the answer: http://forum.dlang.org/thread/1FE961B1-8454-4298-AD8F-16069971EFA1 yahoo.com#post-54BE1AF6.7040805:40dawg.eu https://issues.dlang.org/show_bug.cgi?id=14014 So it looks like it's a DMD bug and we should not include that module. -Steve
Jan 20 2015
parent reply ketmar via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> writes:
On Tue, 20 Jan 2015 07:00:31 -0500
Steven Schveighoffer via Digitalmars-d-learn
<digitalmars-d-learn puremagic.com> wrote:

 On 1/19/15 4:49 PM, Steven Schveighoffer wrote:
=20
 I figured it out, poll.d is missing from here:

 https://github.com/D-Programming-Language/druntime/blob/master/mak/SRCS

 So it's for some reason not purposely included.

 I think there's an expectation (I'm probably guilty of this too) that if
 you include a file somewhere in druntime's core subdirectory, it gets
 compiled in.

 There are actually quite a few files not included... not sure why.
=20 And the answer: http://forum.dlang.org/thread/1FE961B1-8454-4298-AD8F-16069971EFA1 yahoo.=
com#post-54BE1AF6.7040805:40dawg.eu oh, i see, i wasn't thought about moduleinfo and other data.
 https://issues.dlang.org/show_bug.cgi?id=3D14014
=20
 So it looks like it's a DMD bug and we should not include that module.
sorry, i can't see how this bug is related to non-inclusion. actually, it's about the exact opposite! p.s. it it even necessary to generate moduleinfo for modules without initializers and without complex data structures with references?
Jan 20 2015
parent Steven Schveighoffer <schveiguy yahoo.com> writes:
On 1/20/15 9:07 AM, ketmar via Digitalmars-d-learn wrote:
 On Tue, 20 Jan 2015 07:00:31 -0500
 Steven Schveighoffer via Digitalmars-d-learn
 <digitalmars-d-learn puremagic.com> wrote:
 https://issues.dlang.org/show_bug.cgi?id=14014

 So it looks like it's a DMD bug and we should not include that module.
sorry, i can't see how this bug is related to non-inclusion. actually, it's about the exact opposite!
The point is, it generates moduleinfo needlessly.
 p.s. it it even necessary to generate moduleinfo for modules without
 initializers and without complex data structures with references?
A good point. It certainly would make this less of an issue. -Steve
Jan 20 2015
prev sibling parent Steven Schveighoffer <schveiguy yahoo.com> writes:
On 1/19/15 4:27 PM, Steven Schveighoffer wrote:
 On 1/19/15 4:16 PM, ketmar via Digitalmars-d-learn wrote:
 On Mon, 19 Jan 2015 21:00:55 +0000
 tcak via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:

 What is the reason of this error exactly?
"core.sys.posix.poll.d" module is not compiled into druntime. as it is in "include" path, compiler sees it and you can use `pollfd` struct. but as it's not in link library, there is no `.init` section for it.
I think this not the root cause. Of course poll.d should be in druntime, if applicable. What I likely think is that he is compiling on a platform where poll.d is not supported. Can you give more info on your build environment?
I take it back, this happens on my system OSX where it shouldn't. I will investigate, seems like a build bug. -Steve
Jan 19 2015
prev sibling parent ketmar via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> writes:
On Mon, 19 Jan 2015 21:00:55 +0000
tcak via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:

p.s. i love new binutils!

% dmd z00.d
z00.o: In function `D main':
z00.d:(.text._Dmain+0xa): undefined reference to `core.sys.posix.poll.pollf=
d.init$'
z00.d:(.text._Dmain+0x10): undefined reference to `core.sys.posix.poll.poll=
fd.init$'
collect2: error: ld returned 1 exit status
Jan 19 2015