**Background**: I am in the process of creating a visualization for a robot in Unity. The robot's software (and simulator in this case) is all implemented in MATLAB Simulink models and C/C++ code in MEX files.
In order to aid communication with other applications they make use of shared memory. Retrieving and pushing relevant data is thus fairly straightforward, as one can just use a DB get/put to interact with the local real time database. To not get much in the irrelevant details here, this leads to a quite simple single C file, in which I am now just printing the x and y coordinate of one of the robots. Since this all runs on Ubuntu 20.04, I have turned this into an executable that properly prints the robots location in console.
**Problem**: However, I am now faced with the challenge of getting this data into Unity. I have attempted to create a .so file from this C file such that it can be used as a library in Unity. However I always seem to be presented with a `DllNotFoundException` message.
To give you an idea of what I did, here is a simplified impression of the C file:
int end=0;
extern int main(int argc, char *argv[])
{
while(!end) {
printf("PosX : %lf\n",(double)xyz[0]);
printf("PosY : %lf\n",(double)xyz[1]);
usleep(50000);
}
return 0;
}
Next I turned this into a .so file using the following make command:
all-so :
gcc -shared -o libreadKS.so -fPIC readKS.c
After this I have placed the `libreadKS.so` file in `Assets/Plugins/Linux` (I have tried placing it plainly in the `Assets` folder or `Assets/Plugins` as well) and created a simple script in the scene that contains the following:
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEngine;
public class TurtleSimConnectionScript : MonoBehaviour
{
private const string LIBRARY_NAME = "readKS";
[DllImport (LIBRARY_NAME)]
private static extern int main();
void Update() {
main();
}
}
However I always just seem to get `DllNotFoundException: readKS`. Most other cases that run into this issue seem to have included the 'lib' prefix or the .so filetype when passing it in the C# file, but that is not the case here. I have tried using the .so file as provided in the example at the bottom of https://docs.unity3d.com/Manual/AndroidNativePlugins.html , however even this leads to the same result.
My question is if there is something else I am missing/misunderstanding about using .so files in Unity, or are there other (better) ways of approaching this problem?
**Recap:**
*OS*: Ubuntu 20.04
*Unity*: 2020.3.13f1 LTS
Looking to get data from a C file into Unity, either using .so files or another approach.
↧