Created
May 12, 2020 09:33
-
-
Save peterhellberg/821abde4ec13bf54fac5b4ac30d2c96a to your computer and use it in GitHub Desktop.
Example of c-shared libhello.so
This file contains 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 <stdio.h> | |
#include "libhello.h" | |
int main() { | |
printf("Hello World from C!\n"); | |
printf("%s\n", helloWorld()); | |
return 0; | |
} |
This file contains 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" | |
//export helloWorld | |
func helloWorld() *C.char { | |
return C.CString("Hello World from Go!") | |
} | |
func main() {} |
This file contains 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
.PHONY: all build compile clean | |
all: build compile | |
build: | |
go build -buildmode=c-shared -o libhello.so libhello.go | |
compile: | |
cc -o hello hello.c libhello.so | |
clean: | |
rm hello libhello.h libhello.so |
Author
peterhellberg
commented
May 12, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment