2

There is a project in Visual Studio that simulates physics. It uses some functions from the library gsl. I wrote a C++ plugin my plugin.dll to call functions from this project inside Unity. It acts as an interface, where you pass parameters and it calls the project' functions.

Initially the Visual Studio build was generating only myplugin.dll and C# was calling the C++ functions just fine. Probably because the functions it was calling didn't use the gsl functions.

After I added more functions, some of them had to use things from gsl, so when I generate the build, one more file (gsl.dll) was generated.

When I drag all build files (from the x64/Release folder) to Unity Assets folder and run my project, it breaks, giving me this error:

enter image description here

I'm pretty sure the problem is the need of this extra gsl.dll. The functions work fine while testing inside visual studio, so I guess gsl is fine. How can I approach this problem?

Daniel
  • 7,357
  • 7
  • 32
  • 84
  • Static linking doesn't work here? – Brandon Jun 13 '20 at 19:55
  • `When I drag all build files` Could you specify which files you actually copied. The error message indicates that `abort()` is called somewhere, either in your code or the library code, which could be due to a missing or mismatched .dll though it's hard to guess which one without more details. – dxiv Jun 13 '20 at 20:30
  • I copied all the files from the folder **x64/Release** and thrown into Unity **Assets** folder. @Brandon I'm reading about static linking. I just built the `.dll` and called in Unity using `[DllImport("myplugin.dll", CharSet = CharSet.Unicode)] static extern void CreateBall(XBall b);`. It was working until the arrival of the `gsl.dll`, that crashes Unity when I press play. – Daniel Jun 13 '20 at 20:59
  • @Brandon it seems [I can't use static linking with Unity](https://stackoverflow.com/questions/729562/how-to-compile-c-sharp-application-with-c-static-library). – Daniel Jun 13 '20 at 21:16
  • @Daniel That doesn't really tell what DLLs you had in `x64/release` to begin with. Anyway, the stock answer to your question is attach a debugger while the error box is open, and look at the call stack to see what triggered it. – dxiv Jun 13 '20 at 21:57
  • @Daniel statically link `gsl` with your dll so that you have only ONE dll (your plugin).. Then load your plugin in Unity. – Brandon Jun 14 '20 at 03:45
  • How can I do that? gsl is just a #include in my code, I'm new to Visual Studio. – Daniel Jun 14 '20 at 04:42
  • locate that GSL files on your disk, because either there is a dll included there, or you need to build GSL yourself! :( – crsn Jun 15 '20 at 12:33
  • According to specs: A shared version of the library libgsl.so is also installed on systems that support shared libraries. The default location of these files is /usr/local/lib. If this directory is not on the standard search path of your linker you will also need to provide its location as a command line flag. OK. That's about UNIX. To translate it in Windows this means "a DLL version of library is available and it should be available in PATH system variable". So, first make it available. Also there is available static lib that you can use without any system changes. – armagedescu Jun 16 '20 at 10:55
  • 1
    In terms of C# to C++. While you debug your plugin.dll you might have the gsl.dll path available. But it doesn't implicitly mean the gsl.dll will be available for C# while it tries to load your plugin.dll. Because the C# program comes with its own environment. And you should setup the C# environment as well to make the gsl.dll available. Or you have to put the gsl.dll in a place where C# can load it. – armagedescu Jun 16 '20 at 11:00
  • I recall having to do something similar once. Worked fine in testing, wouldn't work during release. Turned out for me the, as was intimated above, that the search path was not what i was expecting it to be. I just put the dll where C# was looking for it instead of coming up with a real solution. – Taekahn Jun 16 '20 at 17:04
  • Are you sure that your Unity project isn't running in 32bit mode? – Brannon Jun 20 '20 at 12:44
  • I'm pretty sure it's running 64bit, but where do I check? – Daniel Jun 20 '20 at 15:14
  • @Daniel maybe is Visial Studio issue.. Are you using 2019? Maybe try to re-run the installer and click Modify and check if the needed Vusial C++ add-ons are installed? – Kos Jun 20 '20 at 19:04
  • Yes, I'm using VS2019. All C++ and C# add-ons are installed. It works fine in VS2019. When it is in Unity, it breaks when I call one of the functions. Some of the functions work, but it seems that when one of them needs to use gsl, it breaks. – Daniel Jun 20 '20 at 19:20
  • @Daniel maybe one thing to try is instead of build in release mode, try to publish and choose framework independent (self contained) application. Then copy over the output from your publish directory.My guess is that gsl requires something that is not installed on your computer... – Kos Jun 22 '20 at 12:57

0 Answers0