Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

iOS native plugin. Linker Error

Discussion in 'iOS and tvOS' started by Rhiojin, Nov 26, 2014.

  1. Rhiojin

    Rhiojin

    Joined:
    Dec 12, 2012
    Posts:
    8
    Hi guys. I'm trying to learn native plugin calls for unity > ObjC by writing a few simple functions and I'm running into an error when trying to build. I'm no Objc expert and yet the error seems deceptively simple:

    Undefined symbols for architecture armv7:
    "_Crap", referenced from:
    RegisterMonoModules() in RegisterMonoModules.o
    ld: symbol(s) not found for architecture armv7
    clang: error: linker command failed with exit code 1 (use -v to see invocation)


    Heres the Objc code----------

    *----PT3.h
    #import <Foundation/Foundation.h>

    @interface PT3: NSObject
    {
    }
    -(int)Crap: (int)c;
    @End
    -----------------------------------------------------------------------------
    *---PT3.m
    #import <Foundation/Foundation.h>
    #import "PT3.h"

    @implementation PT3 : NSObject

    -(int)Crap: (int)c
    {
    // Just returning an int value
    return s * s;
    }

    @End

    In unity I'm following the automatic plugin integration by dragging the .h and .m files into the Asset/Plugins/IOS Folder and then using a tester c# script to load and call the Objc file:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. using System.Runtime.InteropServices;
    5.  
    6. public class test : MonoBehaviour {
    7.  
    8.     public GUIText textObj;
    9.     public GUITexture textureObj;
    10.  
    11.  
    12.     [DllImport ("__Internal")]
    13.     private static extern int Crap(int c);
    14.  
    15.     void Update ()
    16.     {
    17.         if(Input.touchCount > 0)
    18.         {
    19.             if(textureObj.HitTest(Input.GetTouch(0).position))
    20.             {
    21.                 CrapMaker(94);
    22.             }
    23.         }
    24.         else
    25.         {
    26.             if(textureObj.HitTest(Input.mousePosition))
    27.             {
    28.                 CrapMaker(94);
    29.             }
    30.         }
    31.     }
    32.  
    33.  
    34.     public void CrapMaker(int c)
    35.     {
    36.         textObj.text = "Didnt Work";
    37.         int pow = 0;
    38.  
    39.         #if UNITY_IPHONE
    40.         if (Application.platform == RuntimePlatform.IPhonePlayer)
    41.         {
    42.             pow = Crap(c);
    43.             textObj.text = pow.ToString();
    44.         }
    45.         #endif    
    46.    
    47.     }
    48. }
    Ofc whether or not that code works is irrelevant because i cant even build to test. Any ideas?
    I'm using xcode 6.1 and Unity 4.5.5.p2

    I've tried a few things like wrapping the functions in extern"C"{} and changing the .m to a .mm but in that case i get different error where the xcode is unable to find the method declaration for the CrapMaker() function
     
    Last edited: Nov 26, 2014
  2. cbaltzer

    cbaltzer

    Joined:
    Jan 11, 2012
    Posts:
    120
    Rhiojin likes this.
  3. Rhiojin

    Rhiojin

    Joined:
    Dec 12, 2012
    Posts:
    8
    Fantastic reply! Almost seems that blog post was borne of my question. Thanks.
    Now I can start on phase 2.
     
  4. cbaltzer

    cbaltzer

    Joined:
    Jan 11, 2012
    Posts:
    120
    It was, lol. But, I've been meaning to write it for a while, and the same question gets asked a lot, so I figured it was time!