Coder Social home page Coder Social logo

go2wingcc's Introduction

Here we demonstrate how to compile a Go library under Linux, but to be used by C source with gcc on Windows.

Under Linux

Setup the build environment

Pull the official golang docker: (it's a Debian buster)

docker pull golang:1.14

In that container, install mingw w64 gcc:

apt install gcc-mingw-w64

Cross-compile with mingw

Archived version, for static link:

This will produce two files: libaw.a, libaw.h .

GOOS=windows CC=x86_64-w64-mingw32-gcc CGO_ENABLED=1 go build -v -o libaw.a -buildmode=c-archive aw.go

Shared version, for dynamic link:

This will produce two files: aw.dll, aw.h .

GOOS=windows CC=x86_64-w64-mingw32-gcc CGO_ENABLED=1 go build -v -o aw.dll -buildmode=c-shared aw.go

Under Windows

The compiler used is (from gcc --version)

gcc (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 8.1.0

Archived version, for static link:

This will produce a standalone portable c.exe .

gcc -pthread -o c.exe client.c -L. -law

Shared version, for dynamic link:

This will produce a c.exe, which is portable along with aw.dll .

gcc -pthread -o c.exe client.c -L. -law

Or we can cross-compile it on Linux like:

x86_64-w64-mingw32-gcc -pthread -o bin/client.exe client.c -Ibin -Lbin -law

go2wingcc's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.