You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// lib+main.go
package main
import (
"C"
"fmt"
_ "github.com/exporttest/lib"
)
//export ExportedFromMain
func ExportedFromMain() {
fmt.Println("ExportedFromMain")
}
func main() {
// Empty, but required for buildmode=c-shared
}
Run go build -buildmode=c-archive -o libtest.a lib+main.go
Observe that in the header file libtest.h, ExportedFromMain is included, but ExportedFromLib is not.
What did you expect to see?
Both exported functions ExportedFromLib and ExportedFromMain should be exported.
What did you see instead?
ExportedFromLib was not exported in the header file, but it is exported in the generated static library, as the following sample C code shows:
// test.c
#include "libtest.h"
#include <stdio.h>
// Declared here as it does not exist in generated libtest.h
extern void ExportedFromLib();
int main() {
ExportedFromLib();
return 0;
}
C call to static library executes the exported function ExportedFromLib that does not appear in the header file.
The text was updated successfully, but these errors were encountered:
ianlancetaylor
changed the title
Generated header for buildmode=c-archive lacks exported symbols for imported library
cmd/cgo: generated header for buildmode=c-archive lacks exported symbols for imported library
Aug 22, 2018
Yes, that is how it works. The expectation is that your c-archive will only export functions from the main package, just as is done with a normal Go package.
The fact that a symbol marked with //export in some other package winds up being visible in the c-archive is more or less a bug.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Unfortunately, yes.
What operating system and processor architecture are you using (
go env
)?What did you do?
$GOPATH/src/github.com/exporttest
,having contents:
Run
go build -buildmode=c-archive -o libtest.a lib+main.go
Observe that in the header file
libtest.h
,ExportedFromMain
is included, butExportedFromLib
is not.What did you expect to see?
ExportedFromLib
andExportedFromMain
should be exported.What did you see instead?
ExportedFromLib
was not exported in the header file, but it is exported in the generated static library, as the following sample C code shows:ExportedFromLib
that does not appear in the header file.The text was updated successfully, but these errors were encountered: