go-sqlite3: Cross platform build failed
When I tried to build from OS X for Linux, it says:
$ GOOS=linux GOARCH=amd64 go install
# github.com/mattn/go-sqlite3
../../../mattn/go-sqlite3/sqlite3.c:241 unknown #: if
../../../mattn/go-sqlite3/sqlite3.c:256 unknown #: if
../../../mattn/go-sqlite3/sqlite3.c:296 unknown #: if
../../../mattn/go-sqlite3/sqlite3.c:309 unknown #: if
../../../mattn/go-sqlite3/sqlite3.c:339 unknown #: if
../../../mattn/go-sqlite3/sqlite3.c:342 unknown #: elif
../../../mattn/go-sqlite3/sqlite3.c:343 macro redefined: SQLITE_INT_TO_PTR
../../../mattn/go-sqlite3/sqlite3.c:344 macro redefined: SQLITE_PTR_TO_INT
../../../mattn/go-sqlite3/sqlite3.c:345 unknown #: elif
../../../mattn/go-sqlite3/sqlite3.c:346 macro redefined: SQLITE_INT_TO_PTR
../../../mattn/go-sqlite3/sqlite3.c:347 macro redefined: SQLITE_PTR_TO_INT
too many errors
About this issue
- Original URL
- State: closed
- Created 13 years ago
- Comments: 68 (19 by maintainers)
Links to this issue
- Platform_Mirocod/go-sqlite3 at 549fd03c0e9aa19850c8271cbd7cd62bbc884b34 - Platform_Mirocod - Платформа Мирокод
- Platform_Mirocod/go-sqlite3 at release/v1.14 - Platform_Mirocod - Платформа Мирокод
- Platform_Mirocod/go-sqlite3 at c9b9b462d224b953441760bea5fe27adfd435143 - Platform_Mirocod - Платформа Мирокод
- Platform_Mirocod/README.md at 1fbfccb4fc9fc99405174b529206524179177474 - Platform_Mirocod - Платформа Мирокод
- Platform_Mirocod/go-sqlite3 at f34151bdb22c8160b0a6eafef20725ebae1768da - Platform_Mirocod - Платформа Мирокод
- Platform_Mirocod/go-sqlite3 at 3b0303a4fcbb8b8fda258e11edb3fd3c5c09396e - Platform_Mirocod - Платформа Мирокод
- Platform_Mirocod/README.md at release/v1.14 - Platform_Mirocod - Платформа Мирокод
- Platform_Mirocod/go-sqlite3 at 271ab63dfa7d4f54fb8fbfd59906546112ef01fc - Platform_Mirocod - Платформа Мирокод
- Platform_Mirocod/go-sqlite3 at b82293270c7d2d36d79cb9c5731d07c3f5b33f6b - Platform_Mirocod - Платформа Мирокод
- Platform_Mirocod/go-sqlite3 at 273bef1be3e7512c90ff5cc60cd3b633ce1762b7 - Platform_Mirocod - Платформа Мирокод
- Platform_Mirocod/README.md at c0d41b1b77169553006bd9211d025de4da8bafd8 - Platform_Mirocod - Платформа Мирокод
- Platform_Mirocod/README.md at f34151bdb22c8160b0a6eafef20725ebae1768da - Platform_Mirocod - Платформа Мирокод
- Platform_Mirocod/README.md at 3b0303a4fcbb8b8fda258e11edb3fd3c5c09396e - Platform_Mirocod - Платформа Мирокод
- Platform_Mirocod/README.md at cf217befb0c709f65d09756c913e5973b093309c - Platform_Mirocod - Платформа Мирокод
- Platform_Mirocod/go-sqlite3 at f034804e5d98f70d087c2d577a3fb6f0091e742f - Platform_Mirocod - Платформа Мирокод
- Platform_Mirocod/go-sqlite3 at fa96ddb327946eafcf39ab38cbe61bceb91aa649 - Platform_Mirocod - Платформа Мирокод
- Platform_Mirocod/go-sqlite3 at a66ff8a210e950c191bce213d89ec9d51b083224 - Platform_Mirocod - Платформа Мирокод
- reverse/go-sqlite3 at master - reverse - Gitea: Git with a cup of tea
- reverse/go-sqlite3 at master - reverse - Gitea: Git with a cup of tea
- reverse/go-sqlite3 at master - reverse - Gitea: Git with a cup of tea
- xorm-cmd/README.md at master - xorm-cmd - Gitea: Git with a cup of tea
- xorm-dbweb/go-sqlite3 at master - xorm-dbweb - Gitea: Git with a cup of tea
- xorm-cmd/go-sqlite3 at master - xorm-cmd - Gitea: Git with a cup of tea
- reverse/go-sqlite3 at master - reverse - Gitea: Git with a cup of tea
- cmd/README.md at master - cmd - Gitea: Git with a cup of tea
- cmd/go-sqlite3 at master - cmd - Gitea: Git with a cup of tea
- reverse/go-sqlite3 at master - reverse - Gitea: Git with a cup of tea
- reverse/README.md at master - reverse - Gitea: Git with a cup of tea
- reverse/go-sqlite3 at master - reverse - Gitea: Git with a cup of tea
- cmd/README.md at master - cmd - Gitea: Git with a cup of tea
- cmd/go-sqlite3 at master - cmd - Gitea: Git with a cup of tea
Leaving this comment in the hopes it helps someone else in 2016.
Cross compiling Linux (Debian Jessie amd64) -> Windows (amd64) and OSX (amd64) worked for me with the following:
To Windows:
apt-get install gcc_mingw64 env CGO_ENABLED=1 GOOS=windows GOARCH=amd64 CC=x86_64-w64-mingw32-gcc go build $appname
To OSX:
Follow instructions at https://github.com/tpoechtrager/osxcross to build apple cross compiler env CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 CC=o64-clang go build $appname
Ran into similar issue cross-compiling a linux binary on osx. Near as I can tell in my mini investigation, cross-compiling would work except that osx’s implementation of the linker tool (
ld) doesn’t understand the--build-id=noneflag, which is where it chokes. Bothgccandclangattempt to pass this flag along toldregardless of what you do with theCC,GCO_ENABLED, etc environment variables, so it’s simply not gonna work.I have a simple work around using docker which will hopefully help others who don’t want to go through the trouble of recompiling a linux version of
ldfor osx:Note: Naturally a docker workaround will require that you have docker installed 😃
@mattn If you think it’s reasonable feel free to add it to your readme where it will be more visible. I can make a PR as well if you like.
This will put your executable in the expected place, in this case,
$GOPATH/src/path/to/app.You just need to update that
/go/src/path/to/apppart to be your actual directory containing your app, for example,/go/src/path/github.com/username/awesomeSqliteAppIf you want this working in a script like I have (for example I use a python fabric script to build and deploy automatically), you can do the following to prep docker on osx, since otherwise it requires the “Docker Quickstart Terminal”:
In theory this should work on any platform that can run docker, though I’ve only tried on osx.
After some searching, I found a way to cross compilation on OSX:
-ldflags "-linkmode external -extldflags -static"Ex:
Reference: https://blog.filippo.io/easy-windows-and-linux-cross-compilers-for-macos/
Thanks @jeffbmartinez, it got me on the right track to get cross compilation working for Raspberry Pi 3. In case it’s useful for anyone else, here’s the Dockerfile I’m using for OSX:
And the command to build a package from the package directory:
@cprevallet Thank you, (ubuntu)work for windows.
apt-get install gcc-mingw-w64@marcboeker I’ve had good luck using karalabe/xgo to cross-compile go-sqlite3 for ARM devices. Uses a docker linux container, but should be a lot faster than an RPi.