I will use dlang and the dmd compiler (ldc2 works as well) to test this. We will compile our dlang code with the betterC flag to avoid any GC stuff.
We will begin to test dlang -> pb with a static library
myfunc.d
Code: Select all
module myfunc;
extern(C) export int addNumbers(int a, int b)
{
return a + b;
}
Code: Select all
dmd -betterC -m64 -c myfunc.d
polib /out:myfunc.lib myfunc.obj
main.pb
Code: Select all
Import "myfunc.lib"
addNumbers.l(a.l, b.l)
EndImport
Define result = addNumbers(5, 2)
MessageRequester("Result", "D addNumbers(): " + Str(result))
Code: Select all
pbcompiler main.pb
The next step is to export a procedure from pb to dlang to test pb -> dlang
mylib.pb
Code: Select all
ProcedureDLL.l multiplier(value.l)
ProcedureReturn value * 10
EndProcedure
Code: Select all
pbcompiler /dll mylib.pb /output mylib.dll
main.d
Code: Select all
extern(C) int multiplier(int value);
int addNumbers(int a, int b)
{
int sum = a + b;
int result = multiplier(sum);
return result;
}
extern(C) int main()
{
import core.stdc.stdio : printf;
int r = addNumbers(2, 5);
printf("Result: %d\n", r);
return 0;
}
Code: Select all
dmd -betterC main.d mylib.lib -L/subsystem:console -of=maind.exe
Now we want to test pb -> dlang ->pb
However this time we shouldn't be using our mylib.dll, it ought to be possible to export our multiplier procedure during compile time that the static lib can use
myfunc.d
Code: Select all
module myfunc;
extern(C) int multiplier(int value);
extern(C) export int addNumbers(int a, int b)
{
int sum = a + b;
return multiplier(sum);
}
Code: Select all
dmd -betterC -m64 -c myfunc.d
polib /out:myfunc.lib myfunc.obj
Code: Select all
ProcedureDLL.l multiplier(value.l)
ProcedureReturn value * 10
EndProcedure
Import "myfunc.lib"
addNumbers.l(a.l, b.l)
EndImport
Define result = addNumbers(5, 2)
MessageRequester("Result", "D addNumbers(): " + Str(result))
Code: Select all
pbcompiler main.pb
Code: Select all
PureBasic 6.20 (Windows - x64)
Compiling main.pb
Loading external libraries...
Starting compilation...
12 lines processed.
Creating and launching executable.
Error: Linker
error: undefined symbol: multiplier
>>> referenced by myfunc.lib(myfunc.obj):(addNumbers)
I have tested to export with ProcedureC but that didn't make any difference.