Created
December 3, 2015 17:21
-
-
Save oshimaya/d2e0b6057dc553e22c69 to your computer and use it in GitHub Desktop.
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 | |
// cgo test function | |
// build this: | |
// 1. go build -o cgotest1 cgotest.go | |
// 2. go build -o cgotest2 -ldflags='-linkmode=internal' cgotest.go | |
/* | |
#include <stdio.h> | |
__attribute__((constructor)) void cgofunc() { | |
printf("Run CGO function! \n"); | |
} | |
*/ | |
import "C" | |
import "time" | |
func main() { | |
time.Sleep(10*time.Second) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When linkmode is internal, C constructor is not executed...
$ ./cgotest1
Run CGO function!
$ ./cgotest2
$
Then, cgotest1 has the symbol 'cgofunc', but cgotest2 has none.
$ nm cgotest1 | grep cgofunc
0000000000436ca0 T cgofunc
$ nm cgotest2 | grep cgofunc
$