LoginSignup
3
3

More than 5 years have passed since last update.

Go と Objective-C

Last updated at Posted at 2013-06-07
main.go
package main

// #cgo CFLAGS: -x objective-c
// #cgo LDFLAGS: -framework Cocoa
// #import <Cocoa/Cocoa.h>
//
// void SayHello() {
//   NSLog(@"Hello, World!");
// }
//
import "C"

func main() {
        C.SayHello()
}

これだとビルド時ににリンクエラーになるんだよなあ…。 go run -x ... で調べた所、最後の 6l まで行っており、 6l が -framework を解さないのが原因ではないかと考えられる。

追記: できた: https://github.com/hajimehoshi/cocoa_in_go 。原理は、 Objective-C の部分だけ独立した dynamic library にして、 Go から (C の) 関数を呼んでいるだけである。

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3