Written in C ++ using Unity3D calling environment under Ubuntu Linux so dynamic link library

Unity3D community has been supporting Linux version. To Unity3D development program in the Linux environment, you must first install the Linux version of Unity. At the following address:

https://forum.unity3d.com/threads/unity-on-linux-release-notes-and-known-issues.350256/#post-2556301

Dynamic link library under a production Linux

Dynamic link libraries under Linux is .so format. First, we need to write a c ++ file. For simplicity, we can write it as a routine, a file named libtest.cpp

#include <stdio.h>
extern "C" int sum(int a, int b)
{
    return a + b;
}
Open a terminal in the current path of the file, run the following command:

gcc -c -o libtest.o libtest.cpp

gcc -shared -o libtest.so libtest.o

Thus, we get the libtest.so this dynamic link library.


2 Unity3D calls in the dynamic link library

Add script file in C #

[DllImport ("libtest.so", EntryPoint="sum")]
static extern int sum(int a, int b);

The last step in to do the libtest.so file in the root directory unity3D project.

This step is not over, because the Linux environment, Unity3D is not the default search directory that contains the current directory. If it is build out of the program, so we put together files and executable files can be executed; but if it is under Unity debug mode, so the project file in the root directory or in Assets / Plugins, can not be found . In order to facilitate the development, we hope to be like the windows, like in debug mode can also call a dynamic library, so we need to modify / etc / profile, add two lines at the end of the file

LD_LIBRARY_PATH=./

export LD_LIBRARY_PATH

In this way, you can make Unity search for a dynamic link library.

发布了65 篇原创文章 · 获赞 265 · 访问量 55万+

Guess you like

Origin blog.csdn.net/zzlyw/article/details/60463501