Dynamic D Library

"Jérôme M. Berger" jeberger at free.fr
Tue Jul 28 12:11:41 PDT 2009


Daniel Keep wrote:
> 
> teo wrote:
>> On Mon, 27 Jul 2009 20:34:44 +0000, BCS wrote:
>>
>>> Reply to teo,
>>>
>>>> I did some tests and here are the results: D cannot be used in Shared
>>>> Objects. The only case that works is when no classes are exported and
>>>> when there are no references to Phobos within the library.
>>> this works:
>>>
>> no it does not
>>
>>> ...
>> split your files in two directories and compile them separately
> 
> So your justification for it not working is because you deliberately
> didn't follow his instructions and broke the compile?
> 
>> in lib(rary) directory I have test.d
>>
>> module test; // file "test.d"
>> int test1() { return 1; }
>> class Test
>> {
>> 	private int n;
>> 	public this(int i) { n = i; }
>> }
>> $ cd lib/
>> $ dmd -fPIC -c test.d 
>> $ gcc -shared -o libtest.so test.o
>> $ sudo mv libtest.so /opt/lib/
>>
>> and prog.d in exe(cutable) directory
>>
>> module main; // file "prog.d"
>> import std.stdio;
>> import test;
>> void main()
>> {
>> 	writefln("Result: %d", test1());
>> 	Test t = new Test(1);
>> 	return;
>> }
>> $ cd ../exe/
>> $ dmd prog.d -L-L/opt/lib -L-ltest
>> prog.d(2): Error: module test cannot read file 'test.d'
> 
> Well of course it can't compile: YOU MOVED test.d!  What do you expect
> when you tell it to import a file that no longer exists?  The compiler
> is not psychic.
> 
> If you really, absolutely have to have the two parts in different
> directories, just generate a header file.
> 
> dmd -H -c -o- test.d
> 
> That generates test.di, which you have to make available to prog.d.
> 
> Of course, in this particular case, test.di is exactly the same as
> test.d, since all the functions are small enough to be inlined.

	Or just use the -I command line argument to point to the folder in 
which test.d is stored.

		Jerome
-- 
mailto:jeberger at free.fr
http://jeberger.free.fr
Jabber: jeberger at jabber.fr

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: OpenPGP digital signature
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20090728/f0040d9b/attachment.pgp>


More information about the Digitalmars-d mailing list