On Wed, Feb 26, 2020 at 7:07 AM Jan Flyborg <jan.flyb...@gmail.com> wrote:
>
> We are building a system that targets many different combinations of OS's and 
> architectures.
>
> Up until now we have been able to keep the whole code base and external 
> packages in pure Go (no CGO), which means that the cross compiler 
> functionality of GC has been sufficient for us.
>
> However, recently we have introduced a dependency to an SQLite library 
> (https://github.com/mattn/go-sqlite3) which needs CGO and I want to avoid 
> having each developer to install C compilers for all combinations, so I'm 
> investigating if it would be possible to simplify this process.
>
> So let's say I am running Linux/AMD64 on my PC and that my colleague is using 
> a Windows machine. Could I build the CGO part on my machine as an archive 
> file and then ship this archive to my colleagues machine in order to make it 
> possible for him to change GOOS and GOARCH to Linux/AMD64 and thereby 
> enabling him to cross compile (with "go build") for this architecture 
> (without having a C compiler for Linux/AMD64 available)?
>
> Is this possible or do we always have to have a C-toolchain available on the 
> machine where we perform the cross compilation?

You can build the cgo part on your machine and use ld -r to turn the
archive into a single object.  Then you can the object
x_linux_amd64.syso, x_windows_amd64.syso, etc., and distribute those
files.  That will let your users skip the C compilation.  They can set
CGO_ENABLED=0 to skip building the file that does import "C".

But this technique will only work for simple objects that can be
handled by the Go linker in internal linking mode.  It will not work
for C++ code.

Ian

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcWK8_UyAdGQDCs63%3DASSK%2BNcuZLTT8tyWSkJ7CYVaQRdA%40mail.gmail.com.

Reply via email to