cgo -godefs refuses to find glib.h on different machines

287 views
Skip to first unread message

karl....@gmail.com

unread,
Feb 21, 2016, 1:34:36 AM2/21/16
to golang-nuts
Hi,

I'm trying to use:

go tool cgo -godefs defs.go

to generate some definitions. Unfortunately on two machines (OSX 10.11.3 and CentOS6) with v1.5.3, it refuses to find glib.h, failing with:

In file included from vips.h:2,
                 from /home/karl.austin/go/src/mylib/defs.go:6:
/usr/local/include/vips/vips.h:85:18: error: glib.h: No such file or directory
/usr/local/include/vips/vips.h:86:25: error: glib/gstdio.h: No such file or directory
/usr/local/include/vips/vips.h:87:21: error: gmodule.h: No such file or directory
/usr/local/include/vips/vips.h:88:25: error: glib-object.h: No such file or directory

Contents of defs.go:

package mylib

/*
#cgo pkg-config: vips
#include "vips.h"
*/
import "C"

<type defs here>

vips.h has the following includes:

#include <stdlib.h>

#include <vips/vips.h>

#include <vips/vips7compat.h>


Output from pkg-config:

pkg-config --libs vips
-pthread -lvips -lgobject-2.0 -lgthread-2.0 -lrt -lglib-2.0

pkg-config --cflags vips
-pthread -fopenmp -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/libxml2 -I/usr/include/ImageMagick -I/usr/include/libpng12

It's the same if I specify CFLAGS and LDFLAGS manually instead of using pkg-config.  glib.h is in the directory where pkg-config thinks it is:

/usr/include/glib-2.0/glib.h

I'm at a loss as to what to try next.  Any pointers in the right direction would be appreciated, I must be doing something stupid, but I've been staring at it for so long now I can't see what.

Ian Lance Taylor

unread,
Feb 21, 2016, 6:26:15 PM2/21/16
to karl....@gmail.com, golang-nuts
I don't know what is going wrong, but I would passing the -debug-gcc
option to see the exact compilation command that is failing.

Ian

Karl Austin

unread,
Feb 23, 2016, 6:43:31 AM2/23/16
to golang-nuts, karl....@gmail.com

I don't know what is going wrong, but I would passing the -debug-gcc
option to see the exact compilation command that is failing.

Ian

Unfortunately that doesn't shed any more light on what is going wrong, it gets to the point in vips.h where it needs glib.h and fails, also on glib/gstdio.h, gmodule.h, glib-object.h, as you'd probably expect seen as it can't seem to find glib.  Does this on CentOS and OSX still.

Ian Lance Taylor

unread,
Feb 23, 2016, 10:20:24 AM2/23/16
to Karl Austin, golang-nuts
What is the exact compilation command that it is running? Does it
include the right options from pkg-config?

Ian

Karl Austin

unread,
Feb 23, 2016, 10:35:24 AM2/23/16
to golang-nuts, karl....@gmail.com


On Tuesday, 23 February 2016 15:20:24 UTC, Ian Lance Taylor wrote:
What is the exact compilation command that it is running?  Does it
include the right options from pkg-config?

Ian

Sorry, completely missed that:

gcc -E -dM -xc -m64 - <<EOF

So no would appear to be the answer to that.  After that it's just telling me what it has done until it hits the error.  No mention of any of the output from pkg-config. Even if I specify the CFLAGS and LDFLAGS as:

// #cgo CFLAGS: -pthread -fopenmp -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/libxml2 -I/usr/include/ImageMagick -I/usr/include/libpng12
// #cgo LDFLAGS: -pthread -lvips -lgobject-2.0 -lgthread-2.0 -lrt -lglib-2.0

It still doesn't seem to include the output anywhere in what it passes to gcc.

Karl

Ian Lance Taylor

unread,
Feb 23, 2016, 8:34:52 PM2/23/16
to Karl Austin, golang-nuts
My apologies, I was not paying attention. The pkg-config program, and
even the #cgo lines, are handled by the go tool. You aren't using the
go tool; you're invoking cgo directly.

You need to pass the options to cgo on the command line, as documented
at https://golang.org/cmd/cgo/#hdr-Using_cgo_directly

Something along the lines of

go tool cgo -godefs -- `pkg-config --cflags vips` defs.go

Ian
Reply all
Reply to author
Forward
0 new messages