I have simple static lib in xcode with the only class
test.h:
@interface TestClass : NSObject {
NSString *SomeString;
}
@property(nonatomic, readwrite, copy) NSString *SomeString;
- (NSString *) getString;
- (int) getInt;
@end
test.m:
@implementation TestClass
@synthesize SomeString;
- (id)init
{
if ((self = [super init]) == nil)
return nil;
SomeString = @"test string value";
return self;
}
- (NSString *) getString {
return @"Lorem ipsum dolor sit amet";
}
- (int) getInt {
return 123;
}
@end
I’ve copied TstClass from the dll generated by btouch. if i’m using original dll’s implementation:
[Register ("TestClass", true)]
public class TstClass : NSObject
variables Handle, ClassHandle etc are nulls, but app runs and returns nulls as a getInt, getString and SomeString. if I change definition to
[Register ("TestClass")]
public class TstClass : NSObject
inner variables are valid (meaning not null), but app crashes with no output when I’m trying to call a TstClass’s function.
During my research I’ve found someone has fixed this by unchecking “thumb” option in XCode build setting, but I can not find anything that looks like thumb in xcode project. (just in case: XCode 4.2 build 4C199; and I’m using latest version of Monotouch)
How do I create static lib in xcode and use it with monotouch? what’s wrong with my code?
and the last question: I have a .a and its .h files. is there an easier way to generate bindings from library and header files?
it took some time to figure out how to make it work.
Make sure lib and app target architectures are the same. (I had armv7 for lib and armv6 for app)
Make sure build targets are the same (was iOS device for lib and iOS simulator for app. iOS simulator target sets architecture to i386, which makes lib and app build incompatible)
for some reason additional mtouch arguments requires “-cxx -gcc_flags” and not just “-gcc_flags”;
for some reason .a lib was not linked without “-force_load” argument;
add “-v -v -v” to additional mtouch arguments to see full build log. That helped a lot to find this solution.
Thumb instructions set must be disabled (fixed by adding User-defined project option GCC_THUMB_SUPPORT:NO)
that’s it!