golang/go

cmd/cgo: cgo + static const int results in "undefined reference" on linux

Offen

#40.820 geöffnet am 16.08.2020

 (6 Kommentare) (1 Reaktion) (0 zugewiesene Personen)Go (19.008 Forks)batch import
NeedsInvestigationcompiler/runtimehelp wanted

Repository-Metriken

Stars
 (133.883 Sterne)
PR-Merge-Metriken
 (Keine gemergten PRs in 30 T)

Beschreibung

What version of Go are you using (go version)?

Does this issue reproduce with the latest release?

Have not tried

What operating system and processor architecture are you using (go env)?

What did you do?

Linking of a program referring to static const int fails with undefined reference:

foo.h

static const int BAR = 1;

foo.go

package main

/*
#include "foo.h"
*/
import "C"
import "fmt"

const (
  BAR = int(C.BAR)
)

func main() {
  fmt.Println(BAR)
}

What did you expect to see?

Compilation succeeds on linux as it does on darwin

What did you see instead?

go build
/usr/bin/ld: $WORK/b001/_cgo_main.o:/tmp/go-build/cgo-generated-wrappers:2: undefined reference to `BAR'
collect2: error: ld returned 1 exit status

Contributor Guide