Skip to content

Dynamic Shared Embedding

Erik McClure edited this page May 26, 2019 · 1 revision

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:

  1. Download or Install the SDK.
  2. Link to the inNative stub library
  3. 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.

Windows

Stub Library: innative-stub.lib and innative-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.

Manually dynamically linking

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
}

Linux

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.

Manually dynamically linking

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);
}