Compiling C++ software

193 views
Skip to first unread message

Drew Wells

unread,
Apr 19, 2015, 10:27:54 AM4/19/15
to golang-nuts
With swig integration, it's not very easy to link to C++ code by the auto generated code from SWIG. Is it also possible via the Go build chain to provide compile and then link to C++ libraries?

Ian Lance Taylor

unread,
Apr 19, 2015, 10:46:04 AM4/19/15
to Drew Wells, golang-nuts
I'm not sure precisely what you are asking.

You can add a .go file in the directory that does something like

/*
#cgo LDFLAGS: -lmylib
*/
import "C"

That will pass linker options to the go tool.

Ian
Message has been deleted

Ian Lance Taylor

unread,
Apr 20, 2015, 1:42:46 PM4/20/15
to Drew Wells, golang-nuts
On Sun, Apr 19, 2015 at 8:00 AM, Drew Wells <drew.w...@gmail.com> wrote:
>
> I'm linking to C++ which can't be compiled by cgo. However, there is some
> support for autogenerating go code from C++ header information via SWIG. For
> that code to be useful, the C++ library needs to be compiled. Is it possible
> to use the swig features of Go build toolchain to also compile C++
> libraries?

Sorry, I'm still not sure precisely what you are asking.

Perhaps you are saying that you have some C++ files that you wrote,
and you have a SWIG interface that lets you call that C++ code from
Go, and you want the go command to compile all of that. If that is
what you want, you should put the SWIG interface in a .swigcxx file,
and put the C++ code in .cc files, and write a least one .go file, all
in some directory under GOPATH/src. Then the go tool will pass the
.swigcxx file to SWIG, it will pass the C++ files to the C++ compiler,
and pass that .go file to the Go compiler, and will pull them all
together into a single Go package that can be imported by other Go
packages.

Ian
Reply all
Reply to author
Forward
0 new messages