Skip to content

Instantly share code, notes, and snippets.

@ik5
Created January 2, 2020 09:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ik5/e6d6ed84d1678430220fc19d0d136bfa to your computer and use it in GitHub Desktop.
Save ik5/e6d6ed84d1678430220fc19d0d136bfa to your computer and use it in GitHub Desktop.
shared object from go to c (re-take)
#!/usr/bin/env sh
echo "Building go library:"
go build -o libtest.so -buildmode=c-shared ./main.go || exit
echo "Building C executible:"
clang --verbose -DUSE_SHARED_LLVM=on -L/tmp/so -ltest -I/tmp/so main.c -o main -Wall || exit
echo "Done"
#include "./libtest.h"
#include <stdio.h>
int main() {
printf("%d\n", lifeUniverseAndEverything("Hello From C"));
return 0;
}
package main
import "C"
import "fmt"
//export lifeUniverseAndEverything
func lifeUniverseAndEverything(name *C.char) int32 {
fmt.Println(C.GoString(name))
return 42
}
func main() {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment