Skip to content

Instantly share code, notes, and snippets.

@tenntenn
Last active May 12, 2016 07:13
Show Gist options
  • Save tenntenn/1df6a21e859ce99fdd047e0b7e758e19 to your computer and use it in GitHub Desktop.
Save tenntenn/1df6a21e859ce99fdd047e0b7e758e19 to your computer and use it in GitHub Desktop.
UnityのネイティブプラグインをGoで書く #golang #unity ref: http://qiita.com/tenntenn/items/4d3316490a571e5d79ed
$ CGO_ENABLED=1 \
CC=arm-linux-androideabi-gcc \
GOOS=android \
GOARCH=arm \
GOARM=7 \
go build -buildmode=c-shared -o libhoge.so hoge.go
$ cd $GOROOT/src
$ GOROOT_BOOTSTRAP=/path/to/go1.4/ \
GOARM=7 \
CGO_ENABLED=1 \
GOARCH=arm \
CC_FOR_TARGET=`pwd`/../misc/ios/clangwrap.sh \
CXX_FOR_TARGET=`pwd`/../misc/ios/clangwrap.sh ./make.bash
CGO_ENABLED=1 \
GOARCH=arm \
go build -buildmode=c-archive -tags=ios hoge.go
using UnityEngine;
using System.Runtime.InteropServices;
public class Sample : MonoBehaviour
{
#if UNITY_IPHONE
[DllImport("__Internal")]
#else
[DllImport("hoge")]
#endif
private static extern int Hoge();
void Start()
{
var n = Hoge();
Debug.LogFormat("n = {0}", n); // n = 100
}
}
package main
import "C"
//export Hoge
func Hoge() int {
return 100
}
func main() {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment