I am trying to wrap a library with a C++ interface and access it from
golang. The usage is simple, I just need to instantiate a class and call
one or two methods on it. At this point, I don't even care if the
resulting API exposed to golang is a simple C function, but my attempts at
that didn't work, so I am trying swig.
I did follow one of the earlier discussions here, but I am still lost (
https://groups.google.com/forum/#!topic/golang-nuts/ZkGL6hKBfZM/discussion )
The problem, at least the first one I encountered, is that I can't seem to
figure out how to pass the include directive (it takes effect for some of
the gcc invocations, but not for the one that shows error, quoted towards
the end of the email).
My environment is listed below.
$ go version
go version go1.2.1 linux/amd64
$ swig -version
SWIG Version 3.0.0
Compiled with g++ [x86_64-unknown-linux-gnu]
Configured options: +pcre
$ cat device_atlas.go
package main
// #cgo CPPFLAGS: -I/home/harry/DA_cpp_1.5.3.1/include/
import "C"
// no code for now
$ cat device_atlas.swigcxx
%module da
%{
#include <mtld/devatlas.h>
%}
#include <mtld/devatlas.h>
$ go build -x
WORK=/tmp/go-build957195266
mkdir -p $WORK/us.xmpl.hkb/da/_obj/
mkdir -p $WORK/us.xmpl.hkb/da/_obj/exe/
cd /home/harry/go_work/src/us.xmpl.hkb/da
/usr/local/go/pkg/tool/linux_amd64/cgo -objdir $WORK/us.xmpl.hkb/da/_obj/
-- -I/home/harry/DA_cpp_1.5.3.1/include/ -I $WORK/us.xmpl.hkb/da/_obj/
device_atlas.go
/usr/local/go/pkg/tool/linux_amd64/6c -F -V -w -I
$WORK/us.xmpl.hkb/da/_obj/ -I /usr/local/go/pkg/linux_amd64 -o
$WORK/us.xmpl.hkb/da/_obj/_cgo_defun.6 -D GOOS_linux -D GOARCH_amd64
$WORK/us.xmpl.hkb/da/_obj/_cgo_defun.c
gcc -I . -g -O2 -fPIC -m64 -pthread -print-libgcc-file-name
gcc -I . -g -O2 -fPIC -m64 -pthread -I/home/harry/DA_cpp_1.5.3.1/include/
-I $WORK/us.xmpl.hkb/da/_obj/ -o $WORK/us.xmpl.hkb/da/_obj/_cgo_main.o -c
$WORK/us.xmpl.hkb/da/_obj/_cgo_main.c
gcc -I . -g -O2 -fPIC -m64 -pthread -I/home/harry/DA_cpp_1.5.3.1/include/
-I $WORK/us.xmpl.hkb/da/_obj/ -o $WORK/us.xmpl.hkb/da/_obj/_cgo_export.o -c
$WORK/us.xmpl.hkb/da/_obj/_cgo_export.c
gcc -I . -g -O2 -fPIC -m64 -pthread -I/home/harry/DA_cpp_1.5.3.1/include/
-I $WORK/us.xmpl.hkb/da/_obj/ -o
$WORK/us.xmpl.hkb/da/_obj/device_atlas.cgo2.o -c
$WORK/us.xmpl.hkb/da/_obj/device_atlas.cgo2.c
gcc -I . -g -O2 -fPIC -m64 -pthread -o $WORK/us.xmpl.hkb/da/_obj/_cgo_.o
$WORK/us.xmpl.hkb/da/_obj/_cgo_main.o
$WORK/us.xmpl.hkb/da/_obj/_cgo_export.o
$WORK/us.xmpl.hkb/da/_obj/device_atlas.cgo2.o
/usr/local/go/pkg/tool/linux_amd64/cgo -objdir $WORK/us.xmpl.hkb/da/_obj/
-dynimport $WORK/us.xmpl.hkb/da/_obj/_cgo_.o -dynout
$WORK/us.xmpl.hkb/da/_obj/_cgo_import.c
/usr/local/go/pkg/tool/linux_amd64/6c -F -V -w -I
$WORK/us.xmpl.hkb/da/_obj/ -I /usr/local/go/pkg/linux_amd64 -o
$WORK/us.xmpl.hkb/da/_obj/_cgo_import.6 -D GOOS_linux -D GOARCH_amd64
$WORK/us.xmpl.hkb/da/_obj/_cgo_import.c
gcc -I . -g -O2 -fPIC -m64 -pthread -o $WORK/us.xmpl.hkb/da/_obj/_all.o
$WORK/us.xmpl.hkb/da/_obj/_cgo_export.o
$WORK/us.xmpl.hkb/da/_obj/device_atlas.cgo2.o -Wl,-r -nostdlib
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/libgcc.a
cd $WORK
/usr/local/go/pkg/tool/linux_amd64/6g -o ./us.xmpl.hkb/da/_obj/_go_.6 -p
command-line-arguments -complete -D _$WORK ./swig_intsize.go
cd /home/harry/go_work/src/us.xmpl.hkb/da
swig -go -intgosize 64 -module device_atlas -soname
us.xmpl.hkb-da-device_atlas-swigcxx.so -o
$WORK/us.xmpl.hkb/da/_obj/device_atlas_wrap.cxx -outdir
$WORK/us.xmpl.hkb/da/_obj/ -c++ device_atlas.swigcxx
/usr/local/go/pkg/tool/linux_amd64/6c -F -V -w -I
$WORK/us.xmpl.hkb/da/_obj/ -I /usr/local/go/pkg/linux_amd64 -o
$WORK/us.xmpl.hkb/da/_obj/device_atlas_gc.6 -D GOOS_linux -D GOARCH_amd64
$WORK/us.xmpl.hkb/da/_obj/device_atlas_gc.c
gcc -I . -g -O2 -fPIC -m64 -pthread -g -fPIC -O2 -o
$WORK/us.xmpl.hkb/da/_obj/device_atlas_wrap.o -c
$WORK/us.xmpl.hkb/da/_obj/device_atlas_wrap.cxx
# us.xmpl.hkb/da
/tmp/go-build957195266/us.xmpl.hkb/da/_obj/device_atlas_wrap.cxx:221:27:
error: mtld/devatlas.h: No such file or directory
I understand there could be something funky with the devatlas.h appearing
twice (once for swig to parse) and then again inside the %{ %} directive.
I would have thought swig-generated include file should come in the go
headers. But I am just going by whatever I could see in the documentation.
When I remove what is inside those directive and do a build, I get
/tmp/go-build854690558/us.xmpl.hkb/da/_obj/device_atlas.go:13: package
device_atlas; expected main
--
Harry
--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.