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.
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.mystructrather thanC.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.