5

我用shm_opencgo。shm_open在 Linux 上用 3 个参数定义

int shm_open(const char *name, int oflag, mode_t mode);

而在 OSX (Darwin) 上,第 3 模式标志是可选的。

int shm_open(const char *name, int oflag, ...);

当尝试在 OSX 上传递模式时,这会导致 CGO 出现问题。它抱怨我传递了 3 个参数,而预期只有 2 个。

我该如何解决这个问题?

4

1 回答 1

6

像往常一样,在发布到 SO 后 1 秒就会出现启示。您实际上可以在 CGO 注释部分声明函数,因此您所要做的就是使用这样的包装器。

/*
#include <stdio.h>

int shm_open2(const char *name, int oflag, mode_t mode) {
  return shm_open(name, oflag, mode);
}
*/
import "C"
于 2013-11-21T17:55:34.757 回答