• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Imetysaw · Jul 23, 2021 at 03:28 PM · datapluginsdllnotfoundexceptionubuntulibraries

Feeding data into Unity from a Linux executable/.so file?

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

123 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Cannot load native dll in WebGL build 0 Answers

How to handle dependency convergence in Unity? 0 Answers

FileNotFoundException: Could not load file or assembly 0 Answers

DllNotFoundException: File is present 0 Answers

Importing a DLL that contains C#-wrapped C++ Code 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges