Closed goloroden closed 3 days ago
You can use a cross compilation toolchain like https://github.com/messense/homebrew-macos-cross-toolchains Then you can specify the compiler you want to use based on your target OS and arch.
$ brew tap messense/macos-cross-toolchains
$ brew install x86_64-unknown-linux-gnu
$ CC="x86_64-linux-gnu-gcc" CXX="x86_64-linux-gnu-g++" CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build examples/simple.go
$ file simple 6s 23:28:07
simple: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.16, Go BuildID=i6RQPUhd0Xie_bKC0bEu/7m1ok2LyOSc_iqV_yit2/k6vBV4UuwG49abwOIE4s/luX5f5nVpyFsEeykOAZQ, with debug_info, not stripped
Does this work for you?
Windows is a chapter by itself. We're still struggling to get DuckDB cross-compile to Windows.
Yes, this worked – thanks a lot for your help 🎉
I assume that compiling for Linux on ARM would work in a similar way (one needs to figure out what to install for this). And I assume that the same is basically possible the other way round – compiling for macOS, but on Linux.
Given that it's just a few lines, at least if you know what you're doing, wouldn't that be something that could be helpful to add to the documentation?
I am closing this, since my initial question has been answered, and there is a follow-up issue at #279
I am writing an application, using macOS on Apple Silicon.
If I try to compile for this platform, it works:
If I try to compile for macOS on AMD64, it works as well:
(In this case I have not yet tested whether it also actually runs, but at least it compiles without errors.)
Compiling for Linux
So, from the fact that this works I assume that cross-compiling my application with a statically linked DuckDB should be possible. Otherwise, it wouldn't work for AMD64, would it?
However, next I try to compile for Linux on AMD64, using this command:
Now I get an error message:
The same is true for Linux on ARM64 (with the exact same error message):
Compiling for Windows
And I try to compile for Windows on AMD64, I get this error message:
What am I missing? Is cross-compiling my application even possible this way? If so, how?
PS
I'm using
go-duckdb@1.7.0
, and my application so far only initializes an in-memory database, creates a table, and saves a few records, nothing fancy.