Is there a way to Deferred binding symbol from dynamic library?

IchorDev zxinsworld at gmail.com
Fri Nov 29 09:27:08 UTC 2024


On Tuesday, 26 November 2024 at 10:34:07 UTC, Dakota wrote:
> On Saturday, 23 November 2024 at 12:09:22 UTC, IchorDev wrote:
>>
>> Why not load the libraries at runtime and look the pointers up 
>> with symbol names? Or do you really need the compiler to do it 
>> for you?
>
> Because I need link some part static c library, they link 
> global var by symbols name, I can not change this part.
>
>
> What I can do is provide the symbol at runtime, I can not think 
> a way to work around this at runtime.  (maybe for function, but 
> not for global vars)

I'm pretty sure loading the exported symbols of global variables 
works the same way, they'd just be pointers to data instead of to 
code.

```d
__gshared int* foreignLib_some_integer;

//to load:
foreignLib_some_integer = cast(int*)loadSymbol(foreignLib, 
"foreignLib_some_integer");

//using in your code:
if(*foreignLib_some_integer == 10){
   //etc.
}
```


More information about the Digitalmars-d-learn mailing list