In that case - do you know how I can inspect the comparison it's doing? Since I'm already doing this for the open system call, I know that it's possible to write a function with the same definition. It seems in this case that I'm not matching the representation that cgo is expecting. I would therefore like to see what cgo thing it looks like so I can attempt to get a perfect match. Would that be possible?
On Friday, November 3, 2017 at 11:50:36 PM UTC-4, Ian Lance Taylor wrote: > > On Fri, Nov 3, 2017 at 5:44 PM, <tonywa...@gmail.com <javascript:>> > wrote: > > > > Thanks Ian. I had included that because it seems required in order for > me to > > refer to the return type (C.FILE) and so I can access the underlying > C.fopen > > function. This is the approach I have with open but perhaps this is > > different. > > If I'm not supposed to use the include, can you advise how I should > refer to > > the type/function from the header? > > I'm sorry, nothing comes to mind. In C you would just write the > declaration the way the header file expects, but cgo doesn't provide a > way to do that. > > Ian > > > > On Friday, November 3, 2017 at 8:28:38 PM UTC-4, Ian Lance Taylor wrote: > >> > >> On Fri, Nov 3, 2017 at 2:24 PM, <tonywa...@gmail.com> wrote: > >> > > >> > I've been writing a shared-object which I'll use via LD_PRELOAD to > >> > override > >> > the open syscall. This is currently working OK but now I want to move > on > >> > to > >> > fopen. I've defined it (as far as I can tell) in-line with the stdio > >> > header > >> > see here. However, when I try and build: > >> > > >> > $ go build -buildmode=c-shared > >> > # github.com/walkert/loader > >> > In file included from > >> > $WORK/github.com/walkert/loader/_obj/_cgo_export.c:3:0: > >> > ./main.go:56:14: error: conflicting types for ‘fopen’ > >> > In file included from ./main.go:5:0, > >> > from > >> > $WORK/github.com/walkert/loader/_obj/_cgo_export.c:3: > >> > /usr/include/stdio.h:275:14: note: previous declaration of ‘fopen’ > was > >> > here > >> > extern FILE *fopen (const char *__restrict __filename, > >> > ^~~~~ > >> > > >> > /tmp/go-build775342366/ > github.com/walkert/loader/_obj/_cgo_export.c:17:7: > >> > error: conflicting types for ‘fopen’ > >> > FILE* fopen(char* p0, char* p1) > >> > ^~~~~ > >> > In file included from ./main.go:5:0, > >> > from > >> > $WORK/github.com/walkert/loader/_obj/_cgo_export.c:3: > >> > /usr/include/stdio.h:275:14: note: previous declaration of ‘fopen’ > was > >> > here > >> > extern FILE *fopen (const char *__restrict __filename, > >> > ^~~~~ > >> > > >> > I've seen this before when I was trying to return an int instead of > >> > C.int so > >> > I have a feeling I'm missing something simple here. Any pointers > would > >> > be > >> > much appreciated. > >> > >> It looks like the same file is doing #include <stdio.h> and `//export > >> fopen`. That won't work, because, as you can see, the definition of > >> the Go function fopen will conflict with the declaration in stdio.h. > >> > >> Ian > > > > -- > > You received this message because you are subscribed to the Google > Groups > > "golang-nuts" group. > > To unsubscribe from this group and stop receiving emails from it, send > an > > email to golang-nuts...@googlegroups.com <javascript:>. > > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.