I am on Mac.
I have a bunch of C source code (.c
and .h
).
I have a static library (.a
).
I want to use that .a
library from within Unity.
I looked into Unity's documentation for plug-ins (http://unity3d.com/support/documentation/Manual/Plugins.html), which says for PC and Mac stand alones, .bundle
files seem to be the only solution. All example plugin-in projects that Unity give have .bundle
plugins.
But I have seen prime31 plugins using .a
library in Unity!
Anyone has a clue how they did that?
Here is all that I can tell from analyzing prime31 plugin:
(1) they put their .a
library in Unity's Editor folder
(2) they have a C# script which contains lots of [DllImport ("__Internal")]
I tried to do the same:
(1) I wrote a simple hello_world.c in Xcode and built a .a
library. I put the libhelloworld.a
in Asset/Editor
(2) I then wrote a C# script that looks like this:
using UnityEngine;
using System.Collections;
using System.Runtime.InteropServices;
public class testlib : MonoBehaviour {
[DllImport ("libhelloworld")]
static public extern System.String helloworld();
}
(3) Then I wrote a test script:
using UnityEngine;
using System.Collections;
public class test : MonoBehaviour {
// Use this for initialization
void Start () {
print(testlib.helloworld());
}
}
(4) By doing so I get a runtime error:
DllNotFoundException: libhelloworld
test.Start () (at Assets/Script/test.cs:8)
Many, many thanks!
PS: In case some of you wonder why I have the source code but not the bundle. I am trying to build a bundle from those .c
and .h
but hasn't succeeded yet. The source code was compiled with make tools, but I don't know anything else that could build a bundle except for Xcode. So I guess I have to use Xcode to build my bundle. My problem is when I tried to build it with Xcode I get millions of errors saying that I have duplicate main entries. I checked the source code and found that it does have duplicate main()
s because the source code has lots of utilities that come with it. I tried deleting those utilities but the same error doesn't go away...
I am planning to ask this question somewhere else because this does not seem very Unity-related. But if someone here happens to know the answer, please don't hesitate -- let me know!