Re: gdc and gcc object linking issues

2012-06-08 Thread Andrej Mitrovic
On 6/8/12, Kagamin wrote: > Well, I'm not a C++ pro, but I won't recommend to place > initializer in the header. That sounds odd. What would it mean? I > guess, it will mean definition, so chances are it's not what you > want. Initializers belong to definitions, and definitions belong > to .cpp, t

Re: gdc and gcc object linking issues

2012-06-08 Thread Kagamin
On Thursday, 7 June 2012 at 23:58:21 UTC, Andrej Mitrovic wrote: I didn't know I had to either have an initializer in the header or have a .cpp file with the definition. Well, I'm not a C++ pro, but I won't recommend to place initializer in the header. That sounds odd. What would it mean? I

Re: gdc and gcc object linking issues

2012-06-07 Thread Andrej Mitrovic
On 6/7/12, Kagamin wrote: > You didn't define the variable. Aah, I see what's going on. See, I was using this in the context of wrapping existing C++ libs. Since I was writing a small test-case for wrapping a static field I made a header file with a static field declaration but no .cpp implementa

Re: gdc and gcc object linking issues

2012-06-07 Thread Dmitry Olshansky
On 07.06.2012 23:04, Kagamin wrote: On Thursday, 7 June 2012 at 14:29:24 UTC, Regan Heath wrote: In the quoted passage above I suspect he was referring to a static/global variable defined in a C header, not a C++ class member static or otherwise. I'm pretty sure you can define (with storage) g

Re: gdc and gcc object linking issues

2012-06-07 Thread Kagamin
On Thursday, 7 June 2012 at 14:12:56 UTC, Andrej Mitrovic wrote: This wasn't a collision error, it was a missing symbol error. The variable is static, so it should be in the data or bss segment. You seem to be talking about instance variables but that wasn't the issue here. You didn't define

Re: gdc and gcc object linking issues

2012-06-07 Thread Kagamin
On Thursday, 7 June 2012 at 14:29:24 UTC, Regan Heath wrote: In the quoted passage above I suspect he was referring to a static/global variable defined in a C header, not a C++ class member static or otherwise. I'm pretty sure you can define (with storage) global variable in header file both

Re: gdc and gcc object linking issues

2012-06-07 Thread Regan Heath
On Thu, 07 Jun 2012 15:12:46 +0100, Andrej Mitrovic wrote: On 6/7/12, Kagamin wrote: If you define a variable in the header, it will be included in each including module and you'll get several instances of the variable and symbol collision at link time. This wasn't a collision error, it w

Re: gdc and gcc object linking issues

2012-06-07 Thread Andrej Mitrovic
On 6/7/12, Kagamin wrote: > If you define a > variable in the header, it will be included in each including > module and you'll get several instances of the variable and > symbol collision at link time. This wasn't a collision error, it was a missing symbol error. The variable is static, so it sh

Re: gdc and gcc object linking issues

2012-06-07 Thread Kagamin
A class declaration is simply a declaration, it doesn't allocate storage, so members end up being implicitly extern (or static inline for methods with bodies) except for instance fields, whose storage is allocated with the new operator. As static inlining a field has no sense, it becomes extern

Re: gdc and gcc object linking issues

2012-06-06 Thread Andrej Mitrovic
On 6/6/12, Dmitry Olshansky wrote: >> Old boring C++ :) >> >> Once you have this definition due to moronic linkage model (and probably >> some other reasonable things) you have to have: >> >> int Class:statField; > > int Class::statField; obviously Thanks, that fixed it! :) Yeah C++ is a weirdo.

Re: gdc and gcc object linking issues

2012-06-06 Thread Dmitry Olshansky
On 06.06.2012 22:39, Dmitry Olshansky wrote: On 06.06.2012 22:20, Andrej Mitrovic wrote: This is a bit more related to C++ than D, it has to do with wrapping. I've got 4 files: test.h: class Class { public: static int statField; }; Old boring C++ :) Once you have this definition due to moro

Re: gdc and gcc object linking issues

2012-06-06 Thread Dmitry Olshansky
On 06.06.2012 22:20, Andrej Mitrovic wrote: This is a bit more related to C++ than D, it has to do with wrapping. I've got 4 files: test.h: class Class { public: static int statField; }; Old boring C++ :) Once you have this definition due to moronic linkage model (and probably some oth

gdc and gcc object linking issues

2012-06-06 Thread Andrej Mitrovic
This is a bit more related to C++ than D, it has to do with wrapping. I've got 4 files: test.h: class Class { public: static int statField; }; test.cpp: #include "test.h" extern "C" __attribute__((dllexport)) int getStatField() { return Class::statField; } test.d: extern(C) int getStatFi