How to use a function without their sources

nazriel spam at dzfl.pl
Fri Jan 18 10:39:08 PST 2013


On Friday, 18 January 2013 at 18:34:24 UTC, Jordi Sayol wrote:
> Al 18/01/13 18:47, En/na nazriel ha escrit:
>> 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.
>> 
>
> Thanks!
>
> Why it works with "extern(C)", but not works with "extern(D)"?

I shouldn't paste this code in first place.

As far as I know and other folks mentioned there is no "clean" 
way to call function from D library without using .DI files or 
marking function in library as extern (C).

You can always look up symbol table like I did for this example.

Summary:
If you write library - you can mark function as extern (C) to 
call it later from other app without .DI fil.
You need to create .DI file if you use someone else library.


More information about the Digitalmars-d-learn mailing list