Closed calmh closed 10 years ago
This was issue #2, but the author didn't provide any additional information. Does the error go away if you remove const
from int go_codec_init(const CodecCtx*,void**,char**);
in lib/codec.c (line 10)?
Curiously, it doesn't. Looking at it, I would expect it to as well. Also, the error message seems drunk; util.go:35 should hardly be relevant...?
jb@jborg-mbp:~/src/github.com/mxk/go-sqlite/sqlite3 (master) $ git grep go_codec_init
codec.go://export go_codec_init
codec.go:func go_codec_init(ctx *C.CodecCtx, pCodec *unsafe.Pointer, pzErrMsg **C.char) C.int {
lib/codec.c:int go_codec_init(CodecCtx*,void**,char**);
lib/codec.c: if ((rc=go_codec_init(&ctx, &pCodec, &zErrMsg)) != SQLITE_OK) {
jb@jborg-mbp:~/src/github.com/mxk/go-sqlite/sqlite3 (master) $ go build
# github.com/mxk/go-sqlite/sqlite3
In file included from $WORK/github.com/mxk/go-sqlite/sqlite3/_obj/_cgo_export.c:2:
./util.go:35:33: warning: declaration of 'struct __0' will not be visible outside of this function [-Wvisibility]
/var/folders/9y/vgzklz8d48nbkxphhl3bb7yr0000gp/T/go-build908034494/github.com/mxk/go-sqlite/sqlite3/_obj/_cgo_export.c:8:26: warning: declaration of 'struct __0' will not be visible outside of this function [-Wvisibility]
/var/folders/9y/vgzklz8d48nbkxphhl3bb7yr0000gp/T/go-build908034494/github.com/mxk/go-sqlite/sqlite3/_obj/_cgo_export.c:8:5: error: conflicting types for 'go_codec_init'
./util.go:35:12: note: previous declaration is here
Hmm, looking at the autogenerated export file we have the following:
/* Created by cgo - DO NOT EDIT. */
#include "_cgo_export.h"
extern void crosscall2(void (*fn)(void *, int), void *, int);
extern void _cgoexp_ce65b26af501_go_codec_init(void *, int);
int go_codec_init(struct __0* p0, void** p1, char** p2)
{
struct {
struct __0* p0;
void** p1;
char** p2;
int r0;
char __pad0[4];
} __attribute__((__packed__)) a;
a.p0 = p0;
a.p1 = p1;
a.p2 = p2;
crosscall2(_cgoexp_ce65b26af501_go_codec_init, &a, 32);
return a.r0;
}
extern void _cgoexp_ce65b26af501_go_codec_reserve(void *, int);
and I can't actually find the declaration of the struct __0
anywhere. Perhaps this is related to the first visibility warning? I know too little of the stuff cgo generates here to make real sense of it.
So, this is actually a Go compiler bug in 1.3rc1, fixed in https://code.google.com/p/go/issues/detail?id=8148 and can be worked around by this patch on lib/codec.h:
@@ -6,7 +6,7 @@
#define _CODEC_H_
// Codec initialization context.
-typedef struct {
+typedef struct CodecCtr_struct {
sqlite3 *db;
const char *zPath;
const char *zName;
Thanks! I added the struct tag in 167da9432e1f4602e95ea67b67051cfa34412e3f so that the package can be built with 1.3rc1.