cgo 用法示例

file.go内容如下

package main

/*
#cgo linux LDFLAGS: -lrt

#include 
#include 
#include 

#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




你可能感兴趣的:(golang)