DUB fails to build a dynamic library on Linux

2014-12-14 Thread Gabor Mezo via Digitalmars-d

Hello,

I've created a simple db dynamic lib project.

dub.json:

{
"name": "node-d-sample",
"description": "A minimal D application.",
"copyright": "Copyright © 2014, gabor",
"authors": ["gabor"],
"dependencies": {
},
"libs": [ "phobos2" ],
"targetName": "node-d-sample",
"targetPath": "lib",
"targetType": "dynamicLibrary"
}

I have only one source, lib.d:

extern (C)
{
int ping()
{
return 555;
}
}

My system is a Mint x64, dub latest, dmd latest.

If I invoke "dub", then:

Building node-d-sample ~master configuration "library", build 
type debug.

Compiling using dmd...
Linking...
/usr/bin/ld: 
.dub/build/library-debug-linux.posix-x86_64-dmd_2066-44F775BF77E519551012EFF79429BBA3/node-d-sample.o: 
relocation R_X86_64_32 against `.rodata' can not be used when 
making a shared object; recompile with -fPIC
.dub/build/library-debug-linux.posix-x86_64-dmd_2066-44F775BF77E519551012EFF79429BBA3/node-d-sample.o: 
error adding symbols: Bad value

collect2: error: ld returned 1 exit status
--- errorlevel 1
FAIL 
.dub/build/library-debug-linux.posix-x86_64-dmd_2066-44F775BF77E519551012EFF79429BBA3/ 
node-d-sample dynamicLibrary

Error executing command run: dmd failed with exit code 1.


Re: DUB fails to build a dynamic library on Linux

2014-12-14 Thread Gabor Mezo via Digitalmars-d

On Sunday, 14 December 2014 at 16:06:25 UTC, Martin Nowak wrote:

On 12/14/2014 03:50 PM, Gabor Mezo wrote:

Hello,

I've created a simple db dynamic lib project.


https://github.com/D-Programming-Language/dub/issues/352


Thanks,

I've did this, it finally build, but something is still not good.

If I call externals from another application, and my D code 
allocates anything on heap, the calling process crashes with 
SIGSEV. I mean it works:


extern (C)
{
int ping()
{
return 555;
}
}

But it doesn't:

extern (C)
{
int ping()
{
try { throw new Exception("foo"); } catch 
(Exception ex) { }

return 555;
}
}

or this one crashes too:

extern (C)
{
int ping()
{
auto foo = new Object();
return 555;
}
}


Re: DUB fails to build a dynamic library on Linux

2014-12-14 Thread Gabor Mezo via Digitalmars-d

I've opened an other thread instead, because this is a different
issue. It's there:

http://forum.dlang.org/thread/aycvoeaurrpmuehat...@forum.dlang.org#post-aycvoeaurrpmuehatdwp:40forum.dlang.org


Caller of dynamic library crashes with SIGSEV if D code allocates anything on heap.

2014-12-14 Thread Gabor Mezo via Digitalmars-d

Hello,

I've opened an other thread for this, because this is a different 
issue.


Previous issue is there: 
http://forum.dlang.org/thread/zzjeajhjpzhnvgxqu...@forum.dlang.org#post-vuzttuewxyvuihubgtas:40forum.dlang.org


The current issue is if I build a dynamic library with DUB and 
call externals form another application, and my D code

allocates anything on heap, the calling process crashes with
SIGSEV.

I mean it works:

extern (C)
{
int ping()
{
return 555;
}
}

But it doesn't:

extern (C)
{
int ping()
{
try { throw new Exception("foo"); } catch
(Exception ex) { }
return 555;
}
}

or this one crashes too:

extern (C)
{
int ping()
{
auto foo = new Object();
return 555;
}
}


Re: DUB fails to build a dynamic library on Linux

2014-12-14 Thread Gabor Mezo via Digitalmars-d

Thank you for your quick help, that was it.

I do (or at least I'm trying to do) hobbyist D programming as you 
guys, that's why I come here to cry at Sunday evening. :)


Ok, I'm almost there. It builds with DUB/DMD, I can allocate 
stuff on the heap, so far so good. But if I invoke:


dub --compiler=gdc

then I got:

Performing main compilation...
dub build "node-d-sample" --arch=x86_64 --compiler=gdc 
"--build=release"
Building package node-d-sample in 
/home/gabor/sandbox/node-d-sample/
Building node-d-sample ~master configuration "library", build 
type release.

Running gdc...
/usr/bin/ld: 
/usr/lib/gcc/x86_64-linux-gnu/4.9/libgphobos2.a(minfo.o): 
relocation R_X86_64_32 against 
`_D32TypeInfo_APxS6object10ModuleInfo6__initZ' can not be used 
when making a shared object; recompile with -fPIC
/usr/lib/gcc/x86_64-linux-gnu/4.9/libgphobos2.a: error adding 
symbols: Bad value

collect2: error: ld returned 1 exit status
FAIL 
.dub/build/library-release-linux.posix-x86_64-gdc_2065-33A38D9D3DC714C1501A18C957A2B35B/ 
node-d-sample dynamicLibrary

Error executing command build: gdc failed with exit code 1.

Exit code 2
Build complete -- 1 error, 0 warnings

or:

dub --compiler=ldmd2

then I got:

Performing main compilation...
dub build "node-d-sample" --arch=x86_64 --compiler=ldmd2 
"--build=release"
The determined compiler type "ldc" doesn't match the expected 
type "dmd". This will probably result in build errors.
Building package node-d-sample in 
/home/gabor/sandbox/node-d-sample/
Building node-d-sample ~master configuration "library", build 
type release.

Running ldmd2...
/usr/bin/ld: 
/home/gabor/dev/ldc2-0.15.0-beta1-linux-x86_64/bin/../lib/libdruntime-ldc.a(eh.o): 
relocation R_X86_64_32 against `.rodata..str1' can not be used 
when making a shared object; recompile with -fPIC
/home/gabor/dev/ldc2-0.15.0-beta1-linux-x86_64/bin/../lib/libdruntime-ldc.a: 
error adding symbols: Bad value

collect2: error: ld returned 1 exit status
Error: /usr/bin/gcc failed with status: 1
FAIL 
.dub/build/library-release-linux.posix-x86_64-ldc_2066-212B345732639D80C27025028ED586A2/ 
node-d-sample dynamicLibrary

Error executing command build: ldmd2 failed with exit code 1.

Exit code 2
Build complete -- 1 error, 0 warnings

It seems DUB somehow eats dflags away for non DMD compilers. How 
the hell should I prevent this happen? Thanks.


Re: Caller of dynamic library crashes with SIGSEV if D code allocates anything on heap.

2014-12-14 Thread Gabor Mezo via Digitalmars-d

I's solved by ketmar:

"did you called `rt_init()` for your dynamic library? you have to 
do
that in the calling process. and don't forget to call `rt_term()` 
on

exiting."

Yea, I missed that. It works. Thanks.


Re: DUB fails to build a dynamic library on Linux

2014-12-14 Thread Gabor Mezo via Digitalmars-d
Actually I'm practicing D for about three months but this C 
interfacing mumbo jumbo is still missing for me. Ok, I'm go there 
if I'm stuck, thanks.


Re: Lost a new commercial user this week :(

2014-12-14 Thread Gabor Mezo via Digitalmars-d

On Sunday, 14 December 2014 at 20:44:17 UTC, Jacob Carlborg wrote:

On 2014-12-14 09:37, Manu via Digitalmars-d wrote:

They immediately made comments about goto-definition not 
working, and

auto-completion not working reliably.


I'm curious to know which tools they used to get autocompletion 
and go-to-definition to work with JavaScript.


It's Webstorm. There you get auto-completion, go-to-definition, 
refactor, insanely superior debugger, anything that you can dream 
of. I'm not a Jetbrains sales manager, I'm just doing Node.js 
coding at my work. :)