Thread overview
Problem with environ variable (Mac OS X)
Sep 19, 2012
Chris
Sep 19, 2012
Jacob Carlborg
Sep 20, 2012
Chris
Sep 20, 2012
Chris
Sep 21, 2012
Jacob Carlborg
Sep 21, 2012
Chris
Sep 21, 2012
Jacob Carlborg
Sep 21, 2012
Chris
Sep 21, 2012
Jacob Carlborg
Sep 21, 2012
Chris
September 19, 2012
I tried to create a JNI library that - via C - accesses a D function. Calling D from C is not a problem, but when the whole stuff is wrapped into a JNI library, I get the following error message:

Error:
Undefined symbols:
  "_environ", referenced from:
      _environ$non_lazy_ptr in libphobos2.a(process_61b_495.o)
     (maybe you meant: _environ$non_lazy_ptr)

I know it's a Mac specific thing and a fix exists (cf. https://www.gnu.org/software/gnulib/manual/html_node/environ.html), however it doesn't work in my case. process.d accesses environ in a similar way. I am not sure whether I get it all wrong, or whether it isn't possible at all to do the JNI-C-D thing.

I have also read somewhere that JNI could be created directly using D, I haven't found an example, though. Does anyone know anything about it? This would of course be more convenient.
September 19, 2012
On 2012-09-19 12:35, Chris wrote:
> I tried to create a JNI library that - via C - accesses a D function.
> Calling D from C is not a problem, but when the whole stuff is wrapped
> into a JNI library, I get the following error message:
>
> Error:
> Undefined symbols:
>    "_environ", referenced from:
>        _environ$non_lazy_ptr in libphobos2.a(process_61b_495.o)
>       (maybe you meant: _environ$non_lazy_ptr)
>
> I know it's a Mac specific thing and a fix exists (cf.
> https://www.gnu.org/software/gnulib/manual/html_node/environ.html),
> however it doesn't work in my case. process.d accesses environ in a
> similar way. I am not sure whether I get it all wrong, or whether it
> isn't possible at all to do the JNI-C-D thing.
>
> I have also read somewhere that JNI could be created directly using D, I
> haven't found an example, though. Does anyone know anything about it?
> This would of course be more convenient.

A fix for that was applied last year. Which version of the compiler are you using?

https://github.com/D-Programming-Language/phobos/blob/master/std/process.d#L60

-- 
/Jacob Carlborg
September 20, 2012
On Wednesday, 19 September 2012 at 17:31:41 UTC, Jacob Carlborg wrote:
> On 2012-09-19 12:35, Chris wrote:
>> I tried to create a JNI library that - via C - accesses a D function.
>> Calling D from C is not a problem, but when the whole stuff is wrapped
>> into a JNI library, I get the following error message:
>>
>> Error:
>> Undefined symbols:
>>   "_environ", referenced from:
>>       _environ$non_lazy_ptr in libphobos2.a(process_61b_495.o)
>>      (maybe you meant: _environ$non_lazy_ptr)
>>
>> I know it's a Mac specific thing and a fix exists (cf.
>> https://www.gnu.org/software/gnulib/manual/html_node/environ.html),
>> however it doesn't work in my case. process.d accesses environ in a
>> similar way. I am not sure whether I get it all wrong, or whether it
>> isn't possible at all to do the JNI-C-D thing.
>>
>> I have also read somewhere that JNI could be created directly using D, I
>> haven't found an example, though. Does anyone know anything about it?
>> This would of course be more convenient.
>
> A fix for that was applied last year. Which version of the compiler are you using?
>
> https://github.com/D-Programming-Language/phobos/blob/master/std/process.d#L60

Thanks for your answer. I used dmd 2.051 which is still my system default due to compatibility issues (deprecated methods etc.). It didn't occur to me that it's (hopefully) the compiler version, especially because I saw the code snippet in process.d and didn't know it was a recent fix. I'll try the latest version.
September 20, 2012
Thanks a million, Jacob! I have just tested it with the latest version of dmd and it works.
September 21, 2012
On 2012-09-20 21:34, Chris wrote:
> Thanks a million, Jacob! I have just tested it with the latest version
> of dmd and it works.

No problem. You can use DVM if you need the to keep the old version of the compiler.

https://bitbucket.org/doob/dvm

-- 
/Jacob Carlborg
September 21, 2012
On Friday, 21 September 2012 at 06:16:33 UTC, Jacob Carlborg wrote:
> On 2012-09-20 21:34, Chris wrote:
>> Thanks a million, Jacob! I have just tested it with the latest version
>> of dmd and it works.
>
> No problem. You can use DVM if you need the to keep the old version of the compiler.
>
> https://bitbucket.org/doob/dvm

Thanks, that's cool. I really need something like that, because I still use a lot of features that are deprecated by now and are all over the place. The reason for this is that my project developed so fast and grew so big in a short period of time (D speeds up development) that it is hard to trace down all deprecated methods and replace them. Also, the library seems to be changing all the time anyway, so who knows whether or not the new methods will be deprecated again in a few months' time. But as the days are getting shorter I might find the time to skim through the code and finally do the dirty work I keep putting off.
September 21, 2012
On 2012-09-21 10:56, Chris wrote:

> Thanks, that's cool. I really need something like that, because I still
> use a lot of features that are deprecated by now and are all over the
> place. The reason for this is that my project developed so fast and grew
> so big in a short period of time (D speeds up development) that it is
> hard to trace down all deprecated methods and replace them. Also, the
> library seems to be changing all the time anyway, so who knows whether
> or not the new methods will be deprecated again in a few months' time.
> But as the days are getting shorter I might find the time to skim
> through the code and finally do the dirty work I keep putting off.

That's been a quite annoying problem of D. But things have settle down quite a lot in recent times. Hopefully there shouldn't be that much breaking code these days. But if you're relaying on a bug that was fixed it will still break your code.

-- 
/Jacob Carlborg
September 21, 2012
On Friday, 21 September 2012 at 09:50:06 UTC, Jacob Carlborg wrote:
> On 2012-09-21 10:56, Chris wrote:
>
>> Thanks, that's cool. I really need something like that, because I still
>> use a lot of features that are deprecated by now and are all over the
>> place. The reason for this is that my project developed so fast and grew
>> so big in a short period of time (D speeds up development) that it is
>> hard to trace down all deprecated methods and replace them. Also, the
>> library seems to be changing all the time anyway, so who knows whether
>> or not the new methods will be deprecated again in a few months' time.
>> But as the days are getting shorter I might find the time to skim
>> through the code and finally do the dirty work I keep putting off.
>
> That's been a quite annoying problem of D. But things have settle down quite a lot in recent times. Hopefully there shouldn't be that much breaking code these days. But if you're relaying on a bug that was fixed it will still break your code.

Yeah, I see. I didn't realize it was a fixed bug, because I had checked process.d online and thought "Well, it should work". It didn't occur to me that the environ-thing for Mac OS X wasn't included in older versions. But I'll know better the next time!

I hope you are right and things have settled down now, because I would really like to keep on using D and see it take off someday. I have been able to easily integrate my D code into Python, C, Lua (and now hopefully Java) programs and access C libraries easily from D, which - apart from all the nice features the language has to offer - is a real big plus. The only drawback is the lack of a fully-fledged cross-platform GUI, but that's a different story ...
September 21, 2012
On 2012-09-21 16:42, Chris wrote:

> The only drawback is the lack of a fully-fledged
> cross-platform GUI, but that's a different story ...

Have a look at DWT, it's a port of the Java library SWT:

https://github.com/d-widget-toolkit/dwt
http://dsource.org/projects/dwt

I'm currently working on the Mac OS X port.

-- 
/Jacob Carlborg
September 21, 2012
On Friday, 21 September 2012 at 17:02:50 UTC, Jacob Carlborg
wrote:
> On 2012-09-21 16:42, Chris wrote:
>
>> The only drawback is the lack of a fully-fledged
>> cross-platform GUI, but that's a different story ...
>
> Have a look at DWT, it's a port of the Java library SWT:
>
> https://github.com/d-widget-toolkit/dwt
> http://dsource.org/projects/dwt
>
> I'm currently working on the Mac OS X port.

I know of DWT, but being a Mac user I am still not able to
benefit from it as I would like to. But maximum respect that you are working on it.
Keep it up!