0
votes

I try to use the functions from a .bundle file inside Unity3D but every time when I call the functions I get the error:

DllNotFoundException: libant
connectANT.Start () (at Assets/connectANT.cs:13)

This is the script that I use to call the library antlib.bundle which is in the Assets/Plugin folder:

using UnityEngine;
using System.Collections;
using System.Runtime.InteropServices;

public class connectANT : MonoBehaviour {
[DllImport("libant")] static extern bool ANT_Init(int ucUSBDeviceNum_, int ulBaudrate_); 
void Start () {
    ANT_Init (1, 50000);
}
}

in the bundle this function is declared like this:

#ifdef __cplusplus
extern "C" {
#endif
EXPORT BOOL ANT_Init(UCHAR ucUSBDeviceNum_, ULONG ulBaudrate_);  //Initializes and opens USB connection to the module
#ifdef __cplusplus
}
#endif

This is just an example with only one function from the bundle. If I just import the functions in my script I don't get any error in Unity. Can someone help me to figure it out?

2

2 Answers

0
votes

try this:

[DllImport("antlib.bundle")]
static extern int ANT_Init(byte ucUSBDeviceNum_, uint ulBaudrate_); 

there're two problems in your code:

  1. wrong file name
  2. wrong argument type and return type

if you want to use bool as return type, another attribute is required:

[return: System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)]
[DllImport("antlib.bundle")]
static extern bool ANT_Init(byte ucUSBDeviceNum_, uint ulBaudrate_); 
0
votes

Sam is right, your return value and arguments have to match. Also, make sure you bundle includes info.plist with following:

<key>CFBundleExecutable</key>
<string>antlib.dylib</string>

your bundle name and your library name do not have to match, but your plist needs to fix this by pointing to the right lib.