goreleaser / goreleaser-cross

Docker image for Golang cross-compiling with CGO
MIT License
156 stars 26 forks source link

fatal error: bits/libc-header-start.h: No such file or directory #42

Closed mattdesmarais closed 1 year ago

mattdesmarais commented 1 year ago

Hello, i'm trying to run goreleaser-cross:v1.20.5 to build a linux amd64 binary with CGO_ENABLED=1 on my Macbook and it consistnelty fails with - I'm out of ideas.

# runtime/cgo
In file included from _cgo_export.c:3:
/usr/include/stdlib.h:25:10: fatal error: bits/libc-header-start.h: No such file or directory
   25 | #include <bits/libc-header-start.h>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
release-dry-run:
    @docker run \
        --rm \
        -e CGO_ENABLED=1 \
        -v /var/run/docker.sock:/var/run/docker.sock \
        -v /Users/matt/go-workspace/src/rufus:/go/src/rufus \
        -v /Users/matt/go-workspace/src/rufus/sysroot:/rufus \
        -w /go/src/nginxZ/core \
        ghcr.io/goreleaser/goreleaser-cross:v1.20.5 \
        --clean --skip-validate --skip-publish --skip-docker --skip-sign --snapshot --debug
before:
  hooks:
    - sh -c "cd ./core && go mod tidy"
builds:
  - id: linux-amd64
    main: ./core/main.go
    binary: core-linux
    goos:
      - linux
    goarch:
      - amd64
    env:
      - CGO_ENABLED=1
      - CC=x86_64-linux-gnu-gcc
      - CXX=x86_64-linux-gnu-g++
    ldflags:
      - -s -w -X main.version={{.Version}}
  - id: darwin-amd64
    main: ./core/main.go
    binary: core-darwin
    goos:
      - darwin
    goarch:
      - amd64
    env:
      - CGO_ENABLED=1
      - CC=o64-clang
      - CXX=o64-clang++
    ldflags:
      - -s -w -X main.version={{.Version}}

archives:
  - format: tar.gz
    # this name template makes the OS and Arch compatible with the results of uname.
    name_template: >-
      {{ .ProjectName }}_
      {{- title .Os }}_
      {{- if eq .Arch "amd64" }}x86_64
      {{- else if eq .Arch "386" }}i386
      {{- else }}{{ .Arch }}{{ end }}
      {{- if .Arm }}v{{ .Arm }}{{ end }}

checksum:
  name_template: 'checksums.txt'
snapshot:
  name_template: "{{ incpatch .Version }}-next"
changelog:
  sort: asc
  filters:
    exclude:
      - '^docs:'
      - '^test:'
maoueh commented 1 year ago

One thing I have here for such setup is C_INCLUDE_PATH and LIBRARY_PATH as env for this build, like:

  - id: linux-amd64
    main: ./core/main.go
    binary: core-linux
    goos:
      - linux
    goarch:
      - amd64
    env:
      - CGO_ENABLED=1
      - CC=x86_64-linux-gnu-gcc
      - CXX=x86_64-linux-gnu-g++
      - C_INCLUDE_PATH=/usr/x86_64-linux-gnu/include
      - LIBRARY_PATH=/usr/x86_64-linux-gnu/lib
    ldflags:
      - -s -w -X main.version={{.Version}}
troian commented 1 year ago

@mattdesmarais have you tried updating env with CFLAGS: "-I/usr/x86_64-linux-gnu/include"

troian commented 1 year ago

going to close this for now, @mattdesmarais feel free to reopen if issue is still the case