file.go内容如下
package main
/*
#cgo linux LDFLAGS: -lrt
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#define FILE_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
int my_shm_open(char *name) {
return shm_open(name, O_RDWR);
}
*/
import "C"
import (
"fmt"
"unsafe"
)
func main() {
// ...
}
步骤如下:
1. go tool cgo file.go
2.go build file.go
3. ./file