Shared Object with DMD v2.031

2009-07-30 Thread teo
I have difficulties creating a Shared Object (.so) with D. Is it 
possible? Can I use classes defined in the library from the executable?

Here is my library file:
module test; // file test.d
export int testMe() { return 1; }
export class Test
{
private int n;
this(int i) { n = i; }
int get() { return n; }
}

I compile like shown below:
$ dmd -fPIC -c test.d
$ gcc -shared -o libtest.so test.o

I have now a libtest.so and
$ nm libtest.so
shows following:

0860 t 
 U _D10ModuleInfo6__vtblZ
 U _D14TypeInfo_Class6__vtblZ
20b4 V _D20TypeInfo_C4test4Test6__initZ
2060 D _D4test12__ModuleInfoZ
0890 T _D4test4Test3getMFZi
0880 T _D4test4Test6__ctorMFiZC4test4Test
0904 R _D4test4Test6__initZ
0924 R _D4test4Test6__vtblZ
2010 D _D4test4Test7__ClassZ
0874 T _D4test6testMeFZi
 U _D6Object7__ClassZ
 U _D6object6Object5opCmpMFC6ObjectZi
 U _D6object6Object6toHashMFZk
 U _D6object6Object8opEqualsMFC6ObjectZb
 U _D6object6Object8toStringMFZAya
 U _D9ClassInfo6__vtblZ
 U _D9invariant12_d_invariantFC6ObjectZv
1f18 a _DYNAMIC
 U _Dmodule_ref
1ff4 a _GLOBAL_OFFSET_TABLE_
 w _Jv_RegisterClasses
1f08 d __CTOR_END__
1f00 d __CTOR_LIST__
1f10 d __DTOR_END__
1f0c d __DTOR_LIST__
0944 r __FRAME_END__
1f14 d __JCR_END__
1f14 d __JCR_LIST__
20c0 A __bss_start
 w __cxa_finalize@@GLIBC_2.1.3
08b0 t __do_global_ctors_aux
07a0 t __do_global_dtors_aux
200c d __dso_handle
 w __gmon_start__
0857 t __i686.get_pc_thunk.bx
20c0 A _edata
20e0 A _end
08e8 T _fini
0724 T _init
20c0 b completed.6635
20c4 b dtor_idx.6637
0820 t frame_dummy


And this is the program:
module main; // file prog.d
import std.stdio;
import test;
void main()
{
   writefln(testMe: %d, testMe());
   writefln(Test class: %d, (new Test(3)).get());
}

I compile it with:
$ dmd prog.d -L-L`pwd` -L-ltest

And get:
/usr/bin/ld: dynamic variable `_D4test4Test7__ClassZ' is zero size
/usr/bin/ld: prog.o(.text._Dmain+0x26): unresolvable R_386_32 relocation 
against symbol `_D4test4Test7__ClassZ'
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: ld returned 1 exit status
--- errorlevel 1

Please note that _D4test4Test7__ClassZ is defined in the library.

BTW compiling with following works:
$ dmd test.d prog.d


byte to char safe?

2009-07-30 Thread Harry
Again hello, 

char[6] t = ragain ~ cast(char)7 ~ rhello;

use only own write functions
is ok?

thank you!


Re: byte to char safe?

2009-07-30 Thread BCS

Reply to Harry,


Again hello,

char[6] t = ragain ~ cast(char)7 ~ rhello;

use only own write functions
is ok?
thank you!



I think this will also work and you can be shure it's safe.

ragain ~ '\x07' ~ rhello




Re: byte to char safe?

2009-07-30 Thread Ary Borenszweig

Harry escribió:
Again hello, 


char[6] t = ragain ~ cast(char)7 ~ rhello;


If you want the result to be again7hello, then no. You must do:

char[6] t = ragain ~ '7' ~ rhello;

or:

char[6] t = ragain ~ (cast(char)('0' + 7)) ~ rhello;


Re: byte to char safe?

2009-07-30 Thread Harry
Ary Borenszweig Wrote:

 Harry escribió:
  Again hello, 
  
  char[6] t = ragain ~ cast(char)7 ~ rhello;
 
 If you want the result to be again7hello, then no. You must do:
 
 char[6] t = ragain ~ '7' ~ rhello;
 
 or:
 
 char[6] t = ragain ~ (cast(char)('0' + 7)) ~ rhello;

Hello Ary,

7 is data not string.
It makes own write function
need style data in char[]
Not sure if safe ?

thank you



Re: byte to char safe?

2009-07-30 Thread Daniel Keep


Harry wrote:
 Again hello, 
 
 char[6] t = ragain ~ cast(char)7 ~ rhello;
 
 use only own write functions
 is ok?
 
 thank you!

I think a more significant problem is that again\x07hello can't
possibly fit in six characters, unless you're using some crazy numbering
system I'm not familiar with.