I write a program on GoLang with inclusion Objective-C code (call some OSX API) via C
GoLang's package and I need to pass variable of type T
from Go code to Objective-C code and vice versa. T
is structure (or other type). So I need to create compatible (in terms of memory layout) type/variable in GoLang and pass it to Objective-C via unsafe.Pointer
casting. For generic C code I use godefs
in such cases, but I unable to use godefs
for Objective-C. If I try go tool cgo -godefs cgodefs.go
// This is "cgodefs.go" file
package tmp
/*
#cgo CFLAGS: -x objective-c
#cgo LDFLAGS: -framework Cocoa
#import <Cocoa/Cocoa.h>
*/
import "C"
type CGPoint C.CGPoint
I receive tons of errors:
In file included from /Users/unsacrificed/go/src/gui/cgodefs.go:10:
In file included from /System/Library/Frameworks/Cocoa.framework/Headers/Cocoa.h:12:
In file included from /System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:8:
/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:503:1: error: expected identifier or '('
@class NSString, Protocol;
^
/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:505:9: error: unknown type name 'NSString'
typedef NSString * NSExceptionName NS_EXTENSIBLE_STRING_ENUM;
^
/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:506:9: error: unknown type name 'NSString'
typedef NSString * NSRunLoopMode NS_EXTENSIBLE_STRING_ENUM;
... (100000+ lines of errors)
Interested thing is that I can compile and run GoLang apps with Objective-C via C
GoLang's package.
I report to GoLang but he says that
The cgo tool works with C, not Objective-C.
Is there any way to get GoLang equivalent (memory compatible) type for Objective-C type?