Linker error trying to get a native plugin to work

I was wondering if anybody had an idea why I am getting this crazy linker error.
I have a very simple native plugin from the Unity manual.
In Unity, the build settings are for iPhone Device 4.0 and in Xcode, it is likewise.
In Xcode, I have declared (and implemented elsewhere) :

extern "C"
{
	int FooPluginFunction();
}

In Unity, I have attached to a GameObject:

using UnityEngine;
using System.Runtime.InteropServices;

class PluginTest : MonoBehaviour 
{
	[DllImport ("__Internal")]
	public static extern int FooPluginFunction();
	
	void Awake () 
	{
		int x = FooPluginFunction();
	}
}

Here is the linker error:

Undefined symbols:
"_FooPluginFunction", referenced from:
_FooPluginFunction$non_lazy_ptr in RegisterMonoModules.o
(maybe you meant: _FooPluginFunction$non_lazy_ptr)
ld: symbol(s) not found
collect2: ld returned 1 exit status

Any ideas would be great, because I’m out of them! :slight_smile:

I’ve also run into a similar problem trying to get the example iOS plugin code working. I’ve been looking all over the web and the forums for a solution but haven’t found anything, although I have seen several other posts with people experiencing this problem. I’ve been stuck on this for a couple of days so if anyone has any ideas I’d love to hear them. Details below:

I’m trying to build the Bonjour iOS
plugin example found here
http://unity3d.com/support/documentation/Images/manual/iPhoneNativeCodeSample.zip
Linked to from this page

I’m using Unity iPhone Basic Version 3.1.0f4 (55865) and XCode 3.2.5
Building to an iPhone running iOS 4.2.1 (8C148). Here are the steps
I’ve taken when trying to build the project:

  1. Unzip
  2. Open iPhoneNativeCodeSample/Asets/scene.unity
  3. “Upgrading project!” prompt appears, I select Continue
  4. Test Run in Editor appears to work fine with no error/warning
    messages and a Bonjour client dialog box appears
  5. Change Player Settings
    5a) Company Name: bigmutantant
    5b) Productname: appname
    5c) Bundle Identifier: com.bigmutantant.appname
    5d) SDK Version iPhone OS 4.2
    5e) I leave Bundle Version at default of 1.0
    5f) I leave Target iOS Version at 3.0
  6. I select build and run without checking the Debug Build box
  7. Build to the directory PhoneNativeCodeSample/AppName
  8. I get the following errors from XCode

Build Unity-iPhone of project Unity-iPhone with configuration Release

Check dependencies

[BWARN]warning: all apps should include an armv7 architecture (current
ARCHS = “armv6”).

Ld build/appname.app/appname normal armv6
cd /Users/malex/Desktop/iPhoneNativeCodeSample/appname
setenv IPHONEOS_DEPLOYMENT_TARGET 3.0
setenv PATH “/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin”
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/g+±4.2 -arch
armv6 -isysroot
/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk
-L/Users/malex/Desktop/iPhoneNativeCodeSample/PlasmaBlast/build
-L/Users/malex/Desktop/iPhoneNativeCodeSample/PlasmaBlast
-L/Users/malex/Desktop/iPhoneNativeCodeSample/PlasmaBlast/Libraries
-F/Users/malex/Desktop/iPhoneNativeCodeSample/PlasmaBlast/build
-filelist /Users/malex/Desktop/iPhoneNativeCodeSample/PlasmaBlast/build/Unity-iPhone.build/Release-iphoneos/Unity-iPhone.build/Objects-normal/armv6/appname.LinkFileList
-dead_strip -Wl,-S,-x -miphoneos-version-min=3.0 -framework Foundation
-framework UIKit -framework OpenGLES -framework QuartzCore -framework
OpenAL -liconv.2 -liPhone-lib -framework AudioToolbox -framework
CFNetwork -framework MediaPlayer -framework CoreLocation -framework
SystemConfiguration -liPhoneNetwork -o
/Users/malex/Desktop/iPhoneNativeCodeSample/PlasmaBlast/build/appname.app/appname

Undefined symbols:
“__GetServiceName”, referenced from:
__GetServiceName$non_lazy_ptr in RegisterMonoModules.o
(maybe you meant: __GetServiceName$non_lazy_ptr)
“__StartLookup”, referenced from:
__StartLookup$non_lazy_ptr in RegisterMonoModules.o
(maybe you meant: __StartLookup$non_lazy_ptr)
“__GetServiceCount”, referenced from:
__GetServiceCount$non_lazy_ptr in RegisterMonoModules.o
(maybe you meant: __GetServiceCount$non_lazy_ptr)
“__Stop”, referenced from:
__Stop$non_lazy_ptr in RegisterMonoModules.o
(maybe you meant: __Stop$non_lazy_ptr)
“__GetLookupStatus”, referenced from:
__GetLookupStatus$non_lazy_ptr in RegisterMonoModules.o
(maybe you meant: __GetLookupStatus$non_lazy_ptr)
ld: symbol(s) not found
collect2: ld returned 1 exit status

I’ve also tried setting Target Platform to “Universal armv6 + armv7”
and Target IOS Version “4.2” and “Debug Build” with both Release and
Debug in XCode. But no matter what I try, I still get the same
errors. Unity does not show any errors. From what I can tell this
might be an error with how the library is being linked, such as the
symbols not being made available externally. One last issue that I
also noticed is that while the Bundle Identifier was correct on the
first build, on subsequent builds I get the error:

Can’t install application
The Info.plist for application at
/Users/malex/Desktop/iPhoneNativeCodeSample/PlasmaBlast/build/appname.app
specifies a CFBundleExecutable of appname, which does not exist

and have to open the Info.plist and change the Bundle Identifier from
“com.bigmutantant.${PRODUCT_NAME:identifier}” to
“com.bigmutantant.appname”. While this second error is just
moderately annoying, the first one is a big show stopper for me.

Ooop! I just found the ReadMe.txt (donno how I missed that) and added BonjourClientImpl.h/mm to my project as per the instructions. And of course it works just fine. Can’t believe I didn’t RTFM. Instructions copied bellow for reference.

  1. Open project with Unity iPhone 1.1 or later.
  2. Open menu “File->Build Settings…”.
  3. Hit “Build”.
  4. Enter XCode project name and click “Save”.
  5. Open built project with XCode.
  6. Inside XCode: expand “Unity-iPhone” in Groups Files tree.
  7. Right click on “Classes” subfolder and choose “Add->Existing files…”.
  8. In open dialog navigate to the …/Assests/Code folder and select “BonjourClientImpl.h”+“BonjourClientImpl.mm”.
  9. Click “Add”.
  10. Click “Add” once more again.
  11. Click “Build and Go”.
  12. Check application running on device.

I guess you forgot to add "extern “C” when implementing the function :slight_smile:

So, just a follow-up.
I managed to get this working. How?
By throwing out the entire XCode project that Unity generated.
I don’t know what it did, but having it generate a new project and then copying the plugin info into it fixed it and it works.

@mantasp i have changed all those settings… again i got same error as

“_FooPluginFunction”, referenced from:
_FooPluginFunction$non_lazy_ptr in RegisterMonoModules.o
(maybe you meant: _FooPluginFunction$non_lazy_ptr)
ld: symbol(s) not found
collect2: ld returned 1 exit status

i have added "extern “C” " in xCode…why these kind of errors??