How to use a function without their sources

nazriel spam at dzfl.pl
Fri Jan 18 10:17:33 PST 2013


On Friday, 18 January 2013 at 18:10:35 UTC, Maxim Fomin wrote:
> On Friday, 18 January 2013 at 17:47:42 UTC, nazriel wrote:
>> On Friday, 18 January 2013 at 17:02:51 UTC, Jordi Sayol wrote:
>>> Is there a way to use a function from a static D library 
>>> without importing their D sources nor their DI interface?
>>
>> lib.d:
>>
>> extern(C) void printf(const char*, ...);
>>
>> void foo() {
>> 	printf("%s".ptr, "hi".ptr);	
>> }
>>
>> test.d:
>>
>> extern(C) void _D3lib3fooFZv();
>>
>> void main() {
>> 	_D3lib3fooFZv();
>> }
>>
>> Hehe.
>>
>> Now, to be honest that is a good question. How to handle name 
>> mangling?
>> Maybe pragma(mangleOf, "") by Alex Petterson could help.
>
> ----lib.d----
> extern(C) void printf(const char*, ...);
>
> extern(C) void foo() {
>         printf("%s\n".ptr, "hi".ptr);
> }
> ----main.d----
> extern extern(C) void foo();
>
> void main() {
>         foo();
> }
> --------------
>
> # dmd mylib.d -lib -oflibmylib.a
> # dmd main.d -L-lmylib -L-L.
>
> This is possible if inside library non-member functions are 
> marked as extern(C). Otherwise a .di file is needed.

Nice!
This should be mentioned at Language Reference, so it won't get 
lost.



More information about the Digitalmars-d-learn mailing list