[go-nuts] Why does cgo give me "gcc produced no output"?

87 views
Skip to first unread message

Graeme Perrow

unread,
May 20, 2010, 3:52:22 PM5/20/10
to golang-nuts
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. Once I add in the #include for stddef.h, I get
"gcc produced no output" Here is a very simple repro:

***********************************
gptest.h:
#include <stddef.h>
typedef struct mystruct
{
char * buffer;
size_t buffer_size;
size_t * length;
} mystruct;

int myfunc( mystruct *m );

***********************************
gptest.go:
package gptest

// #include "gptest.h"
import "C"

func New() int {
var x = gptest.myfunc();
return x;
}

***********************************
Makefile:
include $(GOROOT)/src/Make.$(GOARCH)

TARG=gptest

CGOFILES=gptest.go

include $(GOROOT)/src/Make.pkg

***********************************
I have searched google, StackOverflow, and this group with no success.

Ian Lance Taylor

unread,
May 20, 2010, 4:54:40 PM5/20/10
to Graeme Perrow, golang-nuts
Graeme Perrow <graeme...@gmail.com> writes:

> func New() int {
> var x = gptest.myfunc();
> return x;
> }

That should be C.myfunc(), not gptest.myfunc(). You call the C
functions using a new package, created by cgo, named "C".

The error message could certainly be better; you may want to open an
issue for that, or just send in a patch.

Ian

Devon H. O'Dell

unread,
May 20, 2010, 5:07:39 PM5/20/10
to Ian Lance Taylor, Graeme Perrow, golang-nuts
2010/5/20 Ian Lance Taylor <ia...@google.com>:
I think that would be a difficult condition to check. The patch might
be to state "Are you using the "C" package?" (or probably something
else more descriptive) in that error message, but the only reason gcc
didn't generate output is because the warning/error stub file that was
created had no symbols since C.foo wasn't used.

I imagine a broken gcc is less likely than this error /
misunderstanding. I guess one way to detect this error would be to
find import "C" without any corresponding symbols in any of the maps
that cgo uses.

I'll send a patch momentarily.

--dho

> Ian
>

Devon H. O'Dell

unread,
May 20, 2010, 5:25:58 PM5/20/10
to Ian Lance Taylor, Graeme Perrow, golang-nuts
Patch in

http://codereview.appspot.com/1193046/show

The error message probably needs work, but this should do it.

--dho

Ian Lance Taylor

unread,
May 20, 2010, 8:36:22 PM5/20/10
to Devon H. O'Dell, Graeme Perrow, golang-nuts
Looks about right to me; send to rsc for review.

Ian
Reply all
Reply to author
Forward
0 new messages