jacksondunstan / UnityNativeScripting

Unity Scripting in C++
https://jacksondunstan.com/articles/3938
MIT License
1.33k stars 135 forks source link

"Exception: Couldn't open native library" on Linux #54

Closed mikkomcmenamin closed 4 years ago

mikkomcmenamin commented 4 years ago

I tried building and using the plugin in Windows and everything worked fine. However, when I built it on Linux and tried running the example bootscene I got the "couldn't open native library" exception.

What I did:

  1. Clone this repo
  2. Go to the Cppsource folder and open terminal
  3. mkdir build
  4. cd build
  5. cmake -G "Unix Makefiles" -DEDITOR=TRUE ..
  6. make
  7. Building went fine and now I have a libNativeScript.so plugin in the Plugins/Editor folder
  8. Open the project with Unity 2019.2.0f1 (also tried 2019.2.17) and run BootScene
  9. Get this error:

Exception: Couldn't open native library: /home/mycompany/Repos/UnityNativeScripting/Unity/Assets/Plugins/Editor/libNativeScript.so NativeScript.Bindings.OpenLibrary (System.String path) (at Assets/NativeScript/Bindings.cs:338) NativeScript.Bindings.OpenPlugin (NativeScript.Bindings+InitMode initMode) (at Assets/NativeScript/Bindings.cs:712) NativeScript.Bindings.Open (System.Int32 memorySize) (at Assets/NativeScript/Bindings.cs:646) NativeScript.BootScript.Start () (at Assets/NativeScript/BootScript.cs:39)

CMake version 3.10.2 and Ubuntu 18.04

Any tips?

mikkomcmenamin commented 4 years ago

Update: I upgraded CMake to latest version 3.16.3 but it didn't make a difference

jacksondunstan commented 4 years ago

Thanks for the detailed description of the issue. I was able to reproduce and found that it was due to passing 0 as the flag/mode of dlopen. In 5f0e56f7c48bdcc71f419740c22a744f0b4b7383, I'm now passing 1 which works on both Linux and macOS.