[GODRIVER-1660] Cannot Cross Compiling from Windows to Linux Using Tags CSE Created: 19/Jun/20 Updated: 27/Oct/23 Resolved: 25/Jun/20 |
|
| Status: | Closed |
| Project: | Go Driver |
| Component/s: | Internal |
| Affects Version/s: | 1.4.0 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Apartemenku Ap | Assignee: | Divjot Arora (Inactive) |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Windows amd64, go version go1.14.4 windows/amd64, mongo-go-driver version v1.4.0+prerelease |
||
| Attachments: |
|
| Description |
|
Currently, I have successfully built an API server with MongoDB CSFLE on Windows Machine for "Windows OS" using this command: set GOOS = windows, GOARCH = amd64 go build -tags cse github.com\user\example_app output: example_app.exe
And then, I try to cross compiling the application for linux with same command, set GOOS=linux, GOARCH = amd64 go build -tags cse github.com\user\example_app output: build failed (screenshot attached) Please help me to solve this issue, Thanks in advance
|
| Comments |
| Comment by Divjot Arora (Inactive) [ 25/Jun/20 ] | ||||||
|
Thanks for your response! I agree that setting up a Linux environment is a much simpler solution than trying to cross-compile from Windows. Because this didn't end up being a driver bug, I'm going to close out this ticket as "Works as Designed". Feel free to leave more comments if you need any help building the driver with CSFLE on Linux, though, and we'd be happy to help out. – Divjot | ||||||
| Comment by Apartemenku Ap [ 25/Jun/20 ] | ||||||
|
Hi Divjot Arora, Yes, I think so, it's about host environment issue and libmongocrypt need specific packages to compile in Linux OS. So I will try to set Linux environment for build this program. Thank you for your help, really appreciate it | ||||||
| Comment by Divjot Arora (Inactive) [ 24/Jun/20 ] | ||||||
|
The closest I found to that error was https://stackoverflow.com/questions/48015645/unknown-type-when-compiling-xz-utils-on-mingw-msys2, which talks about the mingw compiler. Overall, though, I don't think this is a driver bug. I don't have much experience with cross-compilation, but most of the tutorials I'm seeing are for Linux systems, not Windows. My understanding is that you'd have to at least get a Linux toolchain for compiling C. You may also have to set up pkg-config because the driver uses it on Linux and Darwin systems to find the headers and flags needed to compile libmongocrypt and you'd probably have to install libmongocrypt so all of the pkg-config files are in the right place (see https://github.com/mongodb/libmongocrypt#installing-libmongocrypt-from-distribution-packages). | ||||||
| Comment by Apartemenku Ap [ 24/Jun/20 ] | ||||||
|
Hi Divjot Arora, It seems correct after I set CGO_ENABLED = 1 and run build command: I got this error:
I have searched this error in google, but can't find the solution. | ||||||
| Comment by Divjot Arora (Inactive) [ 23/Jun/20 ] | ||||||
|
We don't test cross-compiling cgo-based features in our CI, but this paragraph from https://golang.org/cmd/cgo/#hdr-Using_cgo_with_the_go_command seems like a good start:
My guess is that all of the undefined type errors are due to the fact that cgo is disabled when cross-compiling. So to start, you can try setting CGO_ENABLED=1. Based on the second paragraph, you might also have to set CC to specify which compiler you want to use (like gcc if your target GOOS is linux?). Can you try these suggestions and let us know if you still have issues? Hopefully doing these will at least provide better error messages. – Divjot |