• 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 t$$anonymous$$s 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 pus$$anonymous$$ng 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, t$$anonymous$$s leads to a quite simple single C file, in w$$anonymous$$ch I am now just printing the x and y coordinate of one of the robots. Since t$$anonymous$$s all runs on Ubuntu 20.04, I have turned t$$anonymous$$s into an executable that properly prints the robots location in console.

Problem: However, I am now faced with the challenge of getting t$$anonymous$$s data into Unity. I have attempted to create a .so file from t$$anonymous$$s 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[])
 {
     w$$anonymous$$le(!end) {
         printf("PosX : %lf\n",(double)xyz[0]);
         printf("PosY : %lf\n",(double)xyz[1]);
         usleep(50000);
     }
 
     return 0;
 
 }

Next I turned t$$anonymous$$s into a .so file using the following make command:

 all-so : 
     gcc -shared -o libreadKS.so -fPIC readKS.c

After t$$anonymous$$s 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 t$$anonymous$$s 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 t$$anonymous$$s leads to the same result.

My question is if there is somet$$anonymous$$ng else I am missing/misunderstanding about using .so files in Unity, or are there other (better) ways of approac$$anonymous$$ng t$$anonymous$$s 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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

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

EntryPointNotFoundException - native plugin help 0 Answers

How to properly use my own DLLs in Unity? 2 Answers

Windows 8 - DLLNotFoundException. Windows 7 - No problems! 0 Answers

NuGetForUnity not working with .NET 4.x? 0 Answers

DellNotFoundException only in build 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