2013-08-16 2 views
1

Cython может написать C код, и может cross compile до iOS;Как я могу назвать object-c cython?

Использование Pyobjus можно назвать Objective-C код, но только для работы на OSX, не на iOS, потому что питон не может import _ctypes.

Я знаю kivy можно позвонить по номеру CoreGraphices.Framework через Cython.

kivy/ядро ​​/ изображение/img_imageio.pyx

cdef extern from "CoreGraphics/CGDataProvider.h": 
    ctypedef void *CFDataRef      
    unsigned char *CFDataGetBytePtr(CFDataRef) 

    ctypedef struct CGPoint:      
     float x         
     float y         

    ctypedef struct CGSize:      
     float width        
     float height        

    ctypedef struct CGRect:      
     CGPoint origin       
     CGSize size        

    CGRect CGRectMake(float, float, float, float) 

это мой objective-c код

pyobjc.h

#import <Foundation/Foundation.h> 
@interface PyObjc : NSObject 
-(char *)send:(NSString *)message; 
-(char *)recv; 
@property(nonatomic, strong) NSMutableArray *messageQueue; 
@end 

pyobjc.m

#import "pyobjc.h" 
@implementation PyObjc 
-(id)init{ 
NSLog(@"Init"); 
self.messageQueue = [[NSMutableArray alloc] init]; 
return self; 
} 

-(char *)send:(NSString *)message{ 
NSLog(@"Send: %@", message); 
[self.messageQueue addObject:message]; 
return [message UTF8String]; 
} 

-(char *)recv{ 
NSString *stringback = [self.messageQueue objectAtIndex:0]; 
NSLog(@"Recv: %@",stringback); 
[self.messageQueue removeObjectAtIndex:0]; 
return [stringback UTF8String]; 
} 
@end 

img_ble.pyx

cdef extern from "ble/pyobjc.h":    
    ctypedef char *PyObjcRef     
    char *PySend(PyObjcRef pyoc, char *message) 
    char *PyRecv(PyObjcRef pyoc)    

def send():          
    cdef PyObjcRef pychar      
    p = send("Hello Python")     
    pychar = p         

def recv():          
    cdef PyObjcRef pchar      
    p = recv()         
    pchar = p 

, но я не могу cross compile это для iOS

building 'kivy.core.image.img_ble' extension 
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/arm-apple-darwin10-llvm-gcc-4.2 -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -march=armv7 -mcpu=arm176jzf -mcpu=cortex-a8 -pipe -no-cpp-precomp -miphoneos-version-min=6.1 -O3 -g -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk -I/Users/ygmpkk/Documents/Source_Learn/kivy-ios/tmp/Python-2.7.1/Include -I/Users/ygmpkk/Documents/Source_Learn/kivy-ios/tmp/Python-2.7.1 -c kivy/core/image/img_ble.c -o build/temp.macosx-10.8-x86_64-2.7/kivy/core/image/img_ble.o -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk 
    In file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:8, 
        from kivy/core/image/ble/pyobjc.h:9, 
        from kivy/core/image/img_ble.c:254: 
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:409: error: stray ‘@’ in program 
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:409: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘NSString’ 
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:411: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token 
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:412: error: expected ‘)’ before ‘*’ token 
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:414: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token 
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:415: error: expected ‘)’ before ‘*’ token 
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:417: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token 
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:418: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token 
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:422: error: expected ‘)’ before ‘*’ token 
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:423: error: expected ‘)’ before ‘*’ token 
    In file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObject.h:6, 
        from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSArray.h:5, 
        from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:10, 

ответ

0

Ваш компилятор не обнаружил, что код, который вы хотите скомпилировать является объективно- с. Вы можете:

  1. Переименовать созданный Cython файл из .c в .m
  2. Или сделать .h Objective-C бесплатно, то есть, создать метод C и скрыть Objective-C сложность в .m вашей библиотеки только ,
  3. Или, pybojus напрямую?
+0

Объектив-C может писать C, я исправляю его – Timothy

Смежные вопросы