-
Notifications
You must be signed in to change notification settings - Fork 15
Dynamic Shared Embedding
Dynamically embedding inNative is usually done by statically linking to the innative-stub
project, which itself then dynamically finds an appropriate runtime. Platform-specific alternative methods are also provided, but in general, all platforms must:
- Download or Install the SDK.
- Link to the inNative stub library
- Add the include/innative header files to the project
When dynamically linking, you don't need to distribute the Default Environment, which can be an advantage in certain situations. It's also easier for shared libraries, because the stub automatically finds the installed runtime for you, but this unfortunately requires the user have the runtime installed beforehand.
Stub Library:
innative-stub.lib
andinnative-stub-d.lib
Add the stub library to Additional Dependencies (or your build system's equivalent) like any other static library. Nothing else is required, but ensure the user has installed the runtime beforehand.
If you'd rather link to the library yourself (possibly because you have distributed it with your program and the user hasn't installed it), you can perform the dynamic load yourself:
IRExports exports;
HMODULE dll = LoadLibraryA("your_innative.dll");
if(dll != NULL)
{
void (*hook)(IRExports*) = (void(*)(IRExports*))GetProcAddress((HMODULE)dll, "innative_runtime");
if(hook)
(*hook)(&exports);
else
FreeLibrary(dll); // Only free the library if the function FAILED, we'll need it later if the runtime was loaded correctly
}
Stub Library:
innative-stub.a
Add the static library to your linker step, alongside your .o
files. No additional action is required, but the user must already have the runtime installed, and as of right now there is no installer available for Linux.
If you really want to dynamically link to the library at runtime, but the user doesn't have it installed, you can perform the dynamic load yourself:
IRExports exports;
void* lib = dlopen("your_innative.so", RTLD_NOW);
if(lib != NULL)
{
void(*hook)(IRExports*) = (void(*)(IRExports*))dlsym(lib, "innative_runtime");
if(hook)
(*hook)(&exports);
else
dlclose(lib);
}