douhu3424 2010-05-20 16:37
浏览 92
已采纳

为什么Go似乎无法识别C头文件中的size_t?

I am trying to write a go library that will act as a front-end for a C library. If one of my C structures contains a size_t, I get compilation errors. AFAIK size_t is a built-in C type, so why wouldn't go recognize it?

My header file looks like:

typedef struct mystruct
{
    char *      buffer;
    size_t      buffer_size;
    size_t *    length;
} mystruct;

and the errors I'm getting are:

gcc failed:
In file included from <stdin>:5:
mydll.h:4: error: expected specifier-qualifier-list before 'size_t'

on input:

typedef struct { char *p; int n; } _GoString_;
_GoString_ GoString(char *p);
char *CString(_GoString_);
#include "mydll.h"

I've even tried adding // typedef unsigned long size_t or // #define size_t unsigned long in the .go file before the #include, and then I get "gcc produced no output".

I have seen these questions, and looked over the example with no success.

  • 写回答

3条回答 默认 最新

  • duanlie3187 2010-05-21 13:40
    关注

    The original problem was solved by adding the #include <stddef.h> - thanks Ken and Georg.

    The second problem was that my Go code was using mydll.mystruct rather than C.mystruct, so the C package was not being used at all. There was a bug in the cgo compiler that displayed this error message when the C package was imported and not used. The cgo bug has been fixed (by someone else) to give a more useful error message.

    Details are here.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条
  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
  • ¥188 需要修改一个工具,懂得汇编的人来。
  • ¥15 livecharts wpf piechart 属性
  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了