FAQ
I'm trying to write some bindings for a C library, and the documentation is
kind of sparse on this. How do I set custom variables for the gcc
environment from the build script? For example, I need to set custom
include and link directories, and those values won't be known until the
build actually begins. Unfortunately, I can't use pkg-config or the like
(this build is occurring within a proprietary in-house build system).

I do see the build flags for the cgo tool, but I'm not trying to export Go
symbols into C, I'm just trying to import C symbols into Go.

Thanks.

--

Search Discussions

  • Minux at Oct 4, 2012 at 4:49 am

    On Oct 4, 2012 6:14 AM, "j shagam" wrote:
    I'm trying to write some bindings for a C library, and the documentation
    is kind of sparse on this. How do I set custom variables for the gcc
    environment from the build script? For example, I need to set custom
    include and link directories, and those values won't be known until the
    build actually begins. Unfortunately, I can't use pkg-config or the like
    (this build is occurring within a proprietary in-house build system).
    export CGO_CFLAGS="-Icustom/inc/dir" CGO_LDFLAGS="-Lcustom/lib/dir"
    go build

    --
  • Joseph Poirier at Oct 4, 2012 at 5:02 am

    On Wed, Oct 3, 2012 at 11:49 PM, minux wrote:
    On Oct 4, 2012 6:14 AM, "j shagam" wrote:

    I'm trying to write some bindings for a C library, and the documentation
    is kind of sparse on this. How do I set custom variables for the gcc
    environment from the build script? For example, I need to set custom
    include and link directories, and those values won't be known until the
    build actually begins. Unfortunately, I can't use pkg-config or the like
    (this build is occurring within a proprietary in-house build system).
    export CGO_CFLAGS="-Icustom/inc/dir" CGO_LDFLAGS="-Lcustom/lib/dir"
    go build
    See go/src/make.bash

    --
  • Minux at Oct 4, 2012 at 5:16 am

    On Thu, Oct 4, 2012 at 1:01 PM, Joseph Poirier wrote:
    On Wed, Oct 3, 2012 at 11:49 PM, minux wrote:
    export CGO_CFLAGS="-Icustom/inc/dir" CGO_LDFLAGS="-Lcustom/lib/dir"
    go build
    See go/src/make.bash
    it doesn't document $CGO_CFLAGS and $CGO_LDFLAGS.
    they are documented at golang.org/cmd/cgo

    --
  • Joseph Poirier at Oct 4, 2012 at 8:09 am

    On Thu, Oct 4, 2012 at 12:16 AM, minux wrote:
    On Thu, Oct 4, 2012 at 1:01 PM, Joseph Poirier wrote:
    On Wed, Oct 3, 2012 at 11:49 PM, minux wrote:
    export CGO_CFLAGS="-Icustom/inc/dir" CGO_LDFLAGS="-Lcustom/lib/dir"
    go build
    See go/src/make.bash
    it doesn't document $CGO_CFLAGS and $CGO_LDFLAGS.
    they are documented at golang.org/cmd/cgo
    Along with showing how they're used, there's also some documentation
    there as well. The combination of the two being, IMHO, more
    informative than golang.org/cmd/cgo.

    --
  • Minux at Oct 4, 2012 at 8:26 am

    On Thu, Oct 4, 2012 at 4:08 PM, Joseph Poirier wrote:
    On Thu, Oct 4, 2012 at 12:16 AM, minux wrote:
    On Thu, Oct 4, 2012 at 1:01 PM, Joseph Poirier wrote:
    On Wed, Oct 3, 2012 at 11:49 PM, minux wrote:
    export CGO_CFLAGS="-Icustom/inc/dir" CGO_LDFLAGS="-Lcustom/lib/dir"
    go build
    See go/src/make.bash
    it doesn't document $CGO_CFLAGS and $CGO_LDFLAGS.
    they are documented at golang.org/cmd/cgo
    Along with showing how they're used, there's also some documentation
    there as well. The combination of the two being, IMHO, more
    informative than golang.org/cmd/cgo.
    make.bash only documents GO_GCFLAGS and GO_LDFLAGS, and they are
    only applicable to make.bash (i.e. the go command won't recognize them).

    however, CGO_CFLAGS and CGO_LDFLAGS are applicable to the Go command.

    --
  • J shagam at Oct 4, 2012 at 4:07 pm

    On Wednesday, October 3, 2012 9:50:02 PM UTC-7, minux wrote:
    On Oct 4, 2012 6:14 AM, "j shagam" <jsh...@gmail.com <javascript:>> wrote:

    I'm trying to write some bindings for a C library, and the documentation
    is kind of sparse on this. How do I set custom variables for the gcc
    environment from the build script? For example, I need to set custom
    include and link directories, and those values won't be known until the
    build actually begins. Unfortunately, I can't use pkg-config or the like
    (this build is occurring within a proprietary in-house build system).
    export CGO_CFLAGS="-Icustom/inc/dir" CGO_LDFLAGS="-Lcustom/lib/dir"
    go build
    Thanks. I'd actually found it about an hour after I submitted my question
    but well before my post was approved by the group moderator, but hopefully
    this will help someone else too. Like much of the go docs, it was exactly
    where I'd expect it to be if I already knew where to look for it.

    --

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedOct 3, '12 at 10:14p
activeOct 4, '12 at 4:07p
posts7
users3
websitegolang.org

3 users in discussion

Minux: 3 posts Joseph Poirier: 2 posts J shagam: 2 posts

People

Translate

site design / logo © 2021 Grokbase