Building and linking dynamically from a go binary

前端 未结 5 1860
情书的邮戳
情书的邮戳 2020-12-13 02:51

My problem is the following:

  1. I have a go binary on a machine
  2. From that binary I need to compile an external .go file
  3. Once compiled, I need to
5条回答
  •  心在旅途
    2020-12-13 03:17

    The ability to create shared libraries will be in Go 1.5 in August 2015¹.

    From "The State of Go" talk by Andrew Gerrand:

    Shared libraries

    Go 1.5 can produce Go shared libraries that can be consumed by Go programs.

    Build the standard library as shared libraries:

    $ go install -buildmode=shared std
    

    Build a "Hello, world" program that links against the shared libraries:

    $ go build -linkshared hello.go
    $ ls -l hello
    -rwxr-xr-x 1 adg adg 13926 May 26 02:13 hello
    

    Go 1.5 can also build Go programs as C archive files (for static linking) or shared libraries (for dynamic linking) that can be consumed by C programs.

    [See:] golang.org/s/execmodes

    ¹ Note, gccgo already had limited support for this for some time, Go 1.5 will be the first time this is supported by the regular go build tools.

提交回复
热议问题