On Friday, 7 May 2021 at 08:24:15 UTC, Wusiki jeronii wrote:
> On Friday, 7 May 2021 at 07:36:40 UTC, evilrat wrote:
> On Friday, 7 May 2021 at 06:17:32 UTC, Wusiki jeronii wrote:
> I get the error:
Error: static variable libdll
cannot be read at compile time.
Check how "libdll" and "Library" is defined, this error usually means you are forcing it to CTFE by reading or assigning it to enum, class member initializer, or any other compile time stuff.
> How to redefine template? Need to point all functions by type manually without a template?
What do you mean by redefine template?
Solved.
Library libdll;
T abcd(T)(T a)
{
T function(T) fun = cast(T function(T)) libdll.loadSymbol!(
T function(T))("dll.test");
return fun(a);
}
static this()
{
libdll = Library("libs/libdll.so");
writeln(abcd!float(6.5f));
}
Thanks for your responses.
New problem.
I am getting the error:
object.Exception@source/app.d(67): libs/libdll.so: undefined symbol: _D3dll4testFfZf
But if I will address in my DLL in any place to my template the error disappears.
Example:
Compiles
shared static this()
{
writeln("libdll.so is loaded");
writeln(test!float(7));
}
Does not compiles
shared static this()
{
writeln("libdll.so is loaded");
//writeln(test!float(7));
}
It isn't a problem with pragma. 'cos even without pragma (by _D3dll__T4testHTfZQjFNaNbNiNffZf
) it doesn't work if I will not point to explicit type.
Another example:
I will declare just another function in the DLL source file.
Works
string fff()
{
auto h = test!float(8);
return "";
}
Doesn't work (same error with undefined symbol)
string fff(T)()
{
auto h = test!T(8);
return "";
}
Looks like if I won't explicitly act need template it will not unload as a symbol after building. But it's the library!!! Library of functions. I don't need to address functions in the source code.
So with functions (non-template), there isn't such a problem.