Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cross Compile to Windows From Linux #2

Closed
RadhiFadlillah opened this issue Nov 19, 2016 · 1 comment
Closed

Cross Compile to Windows From Linux #2

RadhiFadlillah opened this issue Nov 19, 2016 · 1 comment

Comments

@RadhiFadlillah
Copy link

RadhiFadlillah commented Nov 19, 2016

As title said, I'm trying to cross compile my app from Ubuntu 64-bit to Windows 32-bit. From issue 106 in go-sqlite3, I've tried this command :

env CGO_ENABLED=1 GOOS=windows GOARCH=386 CC=i686-w64-mingw32-gcc go build

But it failed with this result :

# github.com/xeodou/go-sqlcipher
../github.com/xeodou/go-sqlcipher/sqlite3-binding.c:18280:26: fatal error: openssl/rand.h: No such file or directory
compilation terminated.
@RadhiFadlillah
Copy link
Author

Nevermind guys, I've got it.

  1. Install mingw :

    sudo apt install gcc-mingw-w64

    In Ubuntu 16.04, it will install 64-bit libraries in /usr/x86_64-w64-mingw32 and 32-bit libraries in /usr/i686-w64-mingw32.

  2. Download source code for OpenSSL 1.0.2j here then extract it. Use OpenSSL v1.0.2 because SQLCipher use it.

  3. Cross compile OpenSSL for Windows 32-bit

    In terminal, go to extracted folder, then run configure script to use 32-bit Windows compiler :

    ./Configure mingw shared --cross-compile-prefix=i686-w64-mingw32- --prefix=/usr/i686-w64-mingw32

    After that, run make and sudo make install. After installation finished, I can cross compile my Go app to Windows 32-bit successfully using this command :

    env CGO_ENABLED=1 GOOS=windows GOARCH=386 CC=i686-w64-mingw32-gcc go build
  4. [BONUS] Cross compile OpenSSL for Windows 64-bit

    Go to extracted folder, then run configure script to use 64-bit Windows compiler :

    ./Configure mingw64 shared --cross-compile-prefix=x86_64-w64-mingw32- --prefix=/usr/x86_64-w64-mingw32

    Run make and sudo make install. After installation finished, I can cross compile my Go app to Windows 64-bit successfully :

    env CGO_ENABLED=1 GOOS=windows GOARCH=amd64 CC=x86_64-w64-mingw32-gcc go build

xeodou pushed a commit that referenced this issue May 23, 2018
xeodou pushed a commit that referenced this issue May 23, 2018
Merge lastest from mattn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant