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.