Created
January 2, 2020 09:26
-
-
Save ik5/e6d6ed84d1678430220fc19d0d136bfa to your computer and use it in GitHub Desktop.
shared object from go to c (re-take)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "./libtest.h" | |
#include <stdio.h> | |
int main() { | |
printf("%d\n", lifeUniverseAndEverything("Hello From C")); | |
return 0; | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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