Bug 11898 - Build Issue when using a binding dll to Zebra Third party Library
Summary: Build Issue when using a binding dll to Zebra Third party Library
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: 6.3.x
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2013-04-23 08:28 UTC by Amanda
Modified: 2013-04-24 03:28 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
libZSDK_API.a (1.08 MB, application/octet-stream)
2013-04-23 08:28 UTC, Amanda
Details
ZebraPrinterConnection (6.17 KB, application/octet-stream)
2013-04-23 08:29 UTC, Amanda
Details
ZebraPrinter (4.80 KB, application/octet-stream)
2013-04-23 08:30 UTC, Amanda
Details
DiscoveredPrinter (1.03 KB, application/octet-stream)
2013-04-23 08:32 UTC, Amanda
Details
MfiBTPrinterConnection (8.68 KB, application/octet-stream)
2013-04-23 08:33 UTC, Amanda
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Amanda 2013-04-23 08:28:13 UTC
Created attachment 3847 [details]
libZSDK_API.a

Hi Guys

I would be most grateful if you could spare a moment to have a look at the issue I am having. I am trying to connect and print to a Zebra printer from our iPad app. I have learnt that the iMZ320 printer is compatible with Bluetooth connection to the iPad. I need to link to the relevant libZSDK_API.a library and bind the relevant interfaces, methods and properties. I have created a Xamarin Binding project using the Binding template. I added the libZSDK_API.a and the libZSDK_API.linkwith.cs was created. I have then created the bindings in the APiDefinition.cs I think I need as such:

	[BaseType (typeof (NSObject))]
	[Model]
	interface ZebraPrinterConnection {
		[Export ("open")]
		bool Open();
		
		[Export ("close")]
		void Close();
		
		[Export ("write:error:")]
		int Write(string data, out NSError error);
		
		[Export ("read:")]
		NSData Read(out NSError error);
	}


	[BaseType (typeof (ZebraPrinterConnection))]
	[Model]
	interface MfiBtPrinterConnection {

		[Export ("maxTimeoutForRead")]
		int MaxTimeoutForRead {get;set;}

		[Export ("timeToWaitForMoreData")]
		int TimeToWaitForMoreData {get;set;}

		[Export ("timeToWaitAfterWrite")]
		int TimeToWaitAfterWrite {get;set;}

		[Export ("timeToWaitAfterRead")]
		int TimeToWaitAfterRead {get;set;}

		[Static]
		[Export ("initWithSerialNumber:")]
		IntPtr InitWithSerialNumber(string serialNumber );


	}

	[BaseType (typeof (NSObject))]
	interface ZebraPrinter
	{
	}

	[BaseType (typeof (ZebraPrinter))]
	interface ZebraPrinterCpcl
	{
		[Export ("initWithZebraPrinterConnection:")]
		IntPtr Constructor (ZebraPrinterConnection connection );
	}

	[BaseType (typeof (NSObject))]
	[Model]
	interface FileUtil {



		[Export ("sendFileContents:atError:")]
		bool SendFileContents (string filePath, out NSError error);
	}


	[BaseType (typeof (NSObject))]
	interface DiscoveredPrinter
	{

		//@property (readonly) NSString* address;

		[Export ("address")]
		string Address { get; set; }

	//	- (id)initWithAddress:(NSString *)anAddress;

		[Static]
		[Export ("initWithAddress:")]
		IntPtr InitWithAddress (string address);
	}

This is probably not all I need, but I want to start small at first. 

I have attached the libZSDK_API.a, as well as the relevant headers I used. My dll is created successfully, but when I build my project, referencing a class in it, for example:

ZebraPrinterConnection conn = new ZebraPrinterConnection(MfiBtPrinterConnection.InitWithSerialNumber(serialNumber));

I get the following errors:

Undefined symbols for architecture i386:
  "_OBJC_CLASS_$_EAAccessoryManager", referenced from:
      objc-class-ref in libZSDK_API.a(MfiBtPrinterConnection.o)
  "_OBJC_CLASS_$_EASession", referenced from:
      objc-class-ref in libZSDK_API.a(Zebra_EADSessionController.o)
  "_OBJC_CLASS_$_Linea", referenced from:
      objc-class-ref in libZSDK_API.a(LineaBtPrinterConnection.o)
     (maybe you meant: _OBJC_CLASS_$_LineaBtPrinterConnection)
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status

error MT5202: Native linking failed. Please review the build log.


Do you have any ideas? Can you see if I am doing anything wrong (or right for that matter - never really worked with Objective C before !!)
Comment 1 Amanda 2013-04-23 08:29:57 UTC
Created attachment 3848 [details]
ZebraPrinterConnection
Comment 2 Amanda 2013-04-23 08:30:30 UTC
Created attachment 3849 [details]
ZebraPrinter
Comment 3 Amanda 2013-04-23 08:32:40 UTC
Created attachment 3850 [details]
DiscoveredPrinter
Comment 4 Amanda 2013-04-23 08:33:14 UTC
Created attachment 3851 [details]
MfiBTPrinterConnection
Comment 5 Sebastien Pouliot 2013-04-23 09:27:51 UTC
First, `init*` selectors should be bound as Constructor. You already did it once (for ZebraPrinter), but others are not correct, e.g.

- (id)initWithAddress:(NSString *)anAddress;

should be:

        [Export ("initWithAddress:")]
        IntPtr Constructor (string address);

and not:

        [Static]
        [Export ("initWithAddress:")]
        IntPtr InitWithAddress (string address);


Next, things like

  "_OBJC_CLASS_$_EAAccessoryManager", referenced from:
      objc-class-ref in libZSDK_API.a(MfiBtPrinterConnection.o)
  "_OBJC_CLASS_$_EASession", referenced from:
      objc-class-ref in libZSDK_API.a(Zebra_EADSessionController.o)

means missing symbols. in this case I assume you're missing the ExternalAccessories framework inside your [LinkWith] attribute.

There might be other issues as well. Re-open the bug if that's the case and attach a test case (the full binding project w/test app showing build errors).
Comment 6 Amanda 2013-04-23 10:19:53 UTC
Thanks so much Sebastian

I have changed to the constructor way as you suggested. I am still getting those error tho:

"_OBJC_CLASS_$_EAAccessoryManager", referenced from:
      objc-class-ref in libZSDK_API.a(MfiBtPrinterConnection.o)
  "_OBJC_CLASS_$_EASession", referenced from:
      objc-class-ref in libZSDK_API.a(Zebra_EADSessionController.o)"

You mentioned that I am missing the ExternalAccessories framework inside my [LinkWith attribute. here is the entire contents of my link with.cs:

[assembly: LinkWith ("libZebraSDK.a", LinkTarget.ArmV7, ForceLoad = true)]

Is there another LinkWith I can add? How would I do that?.


Really appreciate the help - feel like a baby learning to walk here...
Comment 7 Sebastien Pouliot 2013-04-23 10:38:15 UTC
Glad to see progress :-)

> Is there another LinkWith I can add? How would I do that?.

See section 5.1.3 of: 
http://docs.xamarin.com/guides/ios/advanced_topics/binding_objective-c_libraries/binding_types_reference_guide

So something like:

[assembly: LinkWith ("libZebraSDK.a", LinkTarget.ArmV7, ForceLoad = true, Frameworks="ExternalAccessory")]

should help.

You should have a look at any existing ObjC sample (inside Xcode) to see which frameworks are referenced, i.e. there might be more requirements (more framework or other options).
Comment 8 Amanda 2013-04-24 03:28:45 UTC
Oooo Sebastian, I am so excited!!

Adding the Accessory Framework to my LinkWith attribute solved the first two errors. Then the error referencing LineaBtPrinterConnection, was solved by another LinkWith attribute to a static class called libdtdev.a, which I found lurking in the demo Xcode project.

Thank you so much for your time and help , most appreciated.


Regards

Amanda