Jump to page: 1 2
Thread overview
Undefined reference error when array size is given
Jan 19, 2015
tcak
Jan 19, 2015
ketmar
Jan 19, 2015
ketmar
Jan 19, 2015
ketmar
Jan 19, 2015
ketmar
Jan 20, 2015
ketmar
Jan 19, 2015
ketmar
January 19, 2015
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?
January 19, 2015
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 = void;` (and don't forget to manually initialise ALL pollfd fields for all array elements then).


January 19, 2015
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.pollfd.init$'
z00.d:(.text._Dmain+0x10): undefined reference to `core.sys.posix.poll.pollfd.init$'
collect2: error: ld returned 1 exit status


January 19, 2015
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
January 19, 2015
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. ;-)


January 19, 2015
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

January 19, 2015
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
January 19, 2015
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.


January 19, 2015
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
January 19, 2015
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, 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.
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.


« First   ‹ Prev
1 2