# How to include a native shared library with custom module?

**URL:** <https://forum.inductiveautomation.com/t/how-to-include-a-native-shared-library-with-custom-module/95440>\
**Category:** Module Development\
**Tags:** ignition81\
**Created:** [September 2, 2024, 7:37pm UTC](https://forum.inductiveautomation.com/t/how-to-include-a-native-shared-library-with-custom-module/95440 "2024-09-02T19:37:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Isaac\_Apodaca](https://avatars.discourse-cdn.com/v4/letter/i/bcef8e/32.png) [@Isaac\_Apodaca](https://forum.inductiveautomation.com/u/Isaac_Apodaca)\
**Post date:** [September 2, 2024, 7:37pm UTC](https://forum.inductiveautomation.com/t/how-to-include-a-native-shared-library-with-custom-module/95440/1 "2024-09-02T19:37:37Z")

</div>

I am building a custom module and am wanting to include a native c shared library. I'm using JNI/JNA in my module code. It's working locally when I run my code. I'm wondering the best way to package the shared library with my module when installing into ignition. Any advice or suggestions are greatly appreciated. Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [September 2, 2024, 8:08pm UTC](https://forum.inductiveautomation.com/t/how-to-include-a-native-shared-library-with-custom-module/95440/2 "2024-09-02T20:08:20Z")

</div>

Package it into the JAR file (if you're using Maven or Gradle this usually just means putting it under `src/main/resources`).

On module startup, extract it to a temporary directory and call [`System.load`](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/System.html#load(java.lang.String)), or if that isn't possible because you're using a jank dependency that doesn't offer you control over the native library loading, extract it to `$IGNITION/lib/core/gateway`, which is already on `java.library.path`.

---

<div class="post-metadata">

**Author:** ![Isaac\_Apodaca](https://avatars.discourse-cdn.com/v4/letter/i/bcef8e/32.png) [@Isaac\_Apodaca](https://forum.inductiveautomation.com/u/Isaac_Apodaca)\
**Post date:** [September 3, 2024, 3:09am UTC](https://forum.inductiveautomation.com/t/how-to-include-a-native-shared-library-with-custom-module/95440/3 "2024-09-03T03:09:34Z")

</div>

This is working perfectly! Thanks for the quick response! I'm packaging the shared libraries in src/main/resources/native. These get copied to the jar file. Then on module startup, I'm able to read the library from the jar file and create a temp file. From there I have the absolute path to read in the shared library using JNA/JNI. Finally, I'm able to call native functions.

One last question. Since I'm writing a temp file which i believe is /tmp on linux and mac and C:\Users\<Username\>\AppData\Local\Temp\ on windows, is there anything I should watch out for? Thanks again for the response!

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [September 3, 2024, 3:19am UTC](https://forum.inductiveautomation.com/t/how-to-include-a-native-shared-library-with-custom-module/95440/4 "2024-09-03T03:19:52Z")

</div>

It might be better to use the temp directory from `SystemManager::getTempDir` ([SystemManager](https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.43/com/inductiveautomation/ignition/gateway/system/SystemManager.html#getTempDir())), and make sure to call [deleteOnExit](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/io/File.html#deleteOnExit()) with your files. This ends up being `$IGNITION/temp` in practice.

The problem with `/tmp` on Linux is that sometimes you get a distro where the temp dir is mounted with the `noexec` flag and then you can't load the libraries from there. But we've done it both ways...

---

<div class="post-metadata">

**Author:** ![Isaac\_Apodaca](https://avatars.discourse-cdn.com/v4/letter/i/bcef8e/32.png) [@Isaac\_Apodaca](https://forum.inductiveautomation.com/u/Isaac_Apodaca)\
**Post date:** [September 3, 2024, 3:23am UTC](https://forum.inductiveautomation.com/t/how-to-include-a-native-shared-library-with-custom-module/95440/5 "2024-09-03T03:23:43Z")

</div>

Got it! Yeah I'll switch to SystemManager temp directory. I actually was using deleteOnExit already so thanks for the confirmation there.
