djimenez / iconv-go

iconv support for Go
BSD 2-Clause "Simplified" License
418 stars 66 forks source link

Cross compile to linux 386 #40

Closed hanspr closed 5 years ago

hanspr commented 5 years ago

Hi,

I'm very new to go, and I have trouble to cross compile a project of mine that uses your library. When I try to compile for linux 386 (on a linux amd64 host) I get this error

$ GOOS=linux GOARCH=386 go build

github.com/djimenez/iconv-go

../github.com/djimenez/iconv-go/reader.go:10:21: undefined: Converter

go version go1.12.6 linux/amd64

Am I missing a flag, package, library I should install, or I have to get a 32 bit Linux and compile in it. I guess is not really an go-iconv issue but I guess you have knowledge for this issue.

Thanks in advance for your help.

Hans

djimenez commented 5 years ago

This library requires CGO

From CGO docs: https://golang.org/cmd/cgo/

The cgo tool is enabled by default for native builds on systems where it is expected to work. It is disabled by default when cross-compiling. You can control this by setting the CGO_ENABLED environment variable when running the go tool: set it to 1 to enable the use of cgo, and to 0 to disable it.

That's probably as much as I can help unfortunately, as I've never tried to cross compile it. As I tell many people who have trouble with cgo or don't realize its required. You should only use this library if you actually need to do conversion with libiconv because of some behavior it has you require. If you don't have such a requirement I suggest you use https://godoc.org/golang.org/x/text/encoding instead - it is pure go.

hanspr commented 5 years ago

Thanks, moved my code to https://godoc.org/golang.org/x/text/encoding, as suggested. Has some encodings missing, but is good for what I need.

097115 commented 4 years ago

Just in case, with osxcross installed, it does compile OK.