Unity Scripting armv7 Error

I’m attempting to write my first unity script. This is the code for a file called TestPlugin.cs that is located in Assets/Plugins:

using UnityEngine; 
using System.Runtime.InteropServices;

public class TestPlugin : MonoBehaviour 
{
    [DllImport ("__Internal")]
    private static extern int getString ();

    public static void Awake () {
      print (getString ());
    }
} 

This is the code for two files that I import into the generated xCode project’s classes folder:

TestPlugin.h:

#import <Foundation/Foundation.h>

@interface TestPlugin : NSObject

-(int)getString;

@end

TestPlugin.m:

#import "TestPlugin.h"

@implementation TestPlugin

- (id)init
{
    self = [super init];
    if (self) {
        // Initialization code here.
    }

    return self;
}

- (int)getString
{
    return 7;
}

@end

Finally this is the javascript file that sits inside the Asset folder.

TestPluginTest.js:

function Update () 
{
TestPlugin.Awake ();
}

Also, please note that i’m not necessarily expecting this all to work, just to compile at this point (though extra pointers and tips are welcome)

The error I get in xCode when trying to build onto iPhone (actual device) is this:

Undefined symbols for architecture armv7:
“_getString”, referenced from:
RegisterMonoModules() in RegisterMonoModules.o
ld: symbol(s) not found for architecture armv7
collect2: ld returned 1 exit status

“_getString”, referenced from:

RegisterMonoModules() in RegisterMonoModules.o

ld: symbol(s) not found for architecture armv7

collect2: ld returned 1 exit status

I’m stumped! Thanks in advance!

your getString() is undefined to linker because there is a declaration mismatch between ’ int getString (void)’ in unity script and
TestPlugin.h

  • (int)getString declared in Objective C TestPlugin class is not equivalent of expected function ‘int getString ()’;
  • (int)getString in objective C has a hidden parameter which is pointer to the instance of TestPlugin.That’s why linker has no
    matched definition of getString.

To resolve the problem create a simple function

extern int getString ()
{
//your definition

return 0;

} ;

in TestPlugin.m before line ‘@implementation TestPlugin’