Using cgo with go modules

475 views
Skip to first unread message

grubia...@gmail.com

unread,
May 6, 2019, 3:37:26 PM5/6/19
to golang-nuts
Hello,
I am trying to adopt my cgo package with go modules.
The cgo project I mentioned above is built using simple Makefile so that I obtain external shared library(.so on Unixes and .dll on Windows) to link external applications(from other modules) with.
When I try to use this module from the other go module the cgo module will be downloaded but failed to build because Makefile won't be run. Is there a way to call Makefile during the automatic build of downloaded cgo package using `go get` or `go build` from an external module that depends on my cgo package?

Ian Lance Taylor

unread,
May 6, 2019, 4:44:09 PM5/6/19
to grubia...@gmail.com, golang-nuts
We've intentionally steered clear of having `go get` or `go build`
invoke `make`. Running `make` can literally do anything on your
system. We don't want that to happen as a side-effect of running the
go tool. At least for now it has to be an explicit decision by the
user. In your case you'll have to document the requirement.

Ian

grubia...@gmail.com

unread,
May 9, 2019, 11:22:43 AM5/9/19
to golang-nuts
Thanks for the reply.
Is there any automatic way to build a dynamic library that cgo-package depends on?

I have the following line in sources of my cgo package(I have the dynamic library libcl3go.so in cwrap folder):
// #cgo LDFLAGS: -Lcwrap/ -lcl3go

When I use `go get <my cgo package>` or `go build <external package that uses the cgo package>` I have got some gotools errors referring the fact that cgo package is downloaded but not built because of `make` hasn't been run and the dynamic library hasn't appeared in cwrap folder.
Maybe there is no point of using separate cgo packages depending on dynamic libraries and I should just include it inside my main package with fully controlled build mechanisms?

понеділок, 6 травня 2019 р. 23:44:09 UTC+3 користувач Ian Lance Taylor написав:

Ian Lance Taylor

unread,
May 9, 2019, 4:51:19 PM5/9/19
to grubia...@gmail.com, golang-nuts
On Thu, May 9, 2019 at 8:21 AM <grubia...@gmail.com> wrote:
>
> Thanks for the reply.
> Is there any automatic way to build a dynamic library that cgo-package depends on?

No, I don't think so.

> I have the following line in sources of my cgo package(I have the dynamic library libcl3go.so in cwrap folder):
> // #cgo LDFLAGS: -Lcwrap/ -lcl3go
>
> When I use `go get <my cgo package>` or `go build <external package that uses the cgo package>` I have got some gotools errors referring the fact that cgo package is downloaded but not built because of `make` hasn't been run and the dynamic library hasn't appeared in cwrap folder.
> Maybe there is no point of using separate cgo packages depending on dynamic libraries and I should just include it inside my main package with fully controlled build mechanisms?

If you want to stick to using only the go tool, then I think that is
your best approach.

Ian
Reply all
Reply to author
Forward
0 new messages