Skip to content

x509 with CGO on OSX #47588

@tcastelly

Description

@tcastelly

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

go version go1.17rc2 darwin/amd64

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/tcastelly/Library/Caches/go-build"
GOENV="/Users/tcastelly/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/tcastelly/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/tcastelly/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/tcastelly/go/go1.17rc2"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/tcastelly/go/go1.17rc2/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.17rc2"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/0n/_2h3pfsn6qz1f4tbs1xzkb3r0000gn/T/go-build689424415=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Hello,

I'm trying to call Golang from Rust using a build like this:

go build -buildmode=c-archive -o mylib.a main.go
// main.go

import (
	"C"
	"crypto/x509"
	"fmt"
)

//export PrintCerts
func PrintCerts() bool {
	start := time.Now()
	certs, err := x509.SystemCertPool()
	end := time.Now()
	if err != nil {
		panic(err)
	}
	fmt.Printf("found %d certs in %v\n", len(certs.Subjects()), end.Sub(start))

	return true
}

And when I call it I have this error:

Undefined symbols for architecture x86_64:
            "_SecTrustSettingsCopyTrustSettings", referenced from:
                _crypto/x509/internal/macos.x509_SecTrustSettingsCopyTrustSettings_trampoline in libgophernize.a(go.o)
            "_SecPolicyCopyProperties", referenced from:
                _crypto/x509/internal/macos.x509_SecPolicyCopyProperties_trampoline in libgophernize.a(go.o)
            "_SecItemExport", referenced from:
                _crypto/x509/internal/macos.x509_SecItemExport_trampoline in libgophernize.a(go.o)
            "_SecTrustSettingsCopyCertificates", referenced from:
                _crypto/x509/internal/macos.x509_SecTrustSettingsCopyCertificates_trampoline in libgophernize.a(go.o)
            "_CFNumberGetValue", referenced from:
                _crypto/x509/internal/macos.x509_CFNumberGetValue_trampoline in libgophernize.a(go.o)
            "_CFDictionaryGetValueIfPresent", referenced from:
                _crypto/x509/internal/macos.x509_CFDictionaryGetValueIfPresent_trampoline in libgophernize.a(go.o)
            "_CFDataGetLength", referenced from:
                _crypto/x509/internal/macos.x509_CFDataGetLength_trampoline in libgophernize.a(go.o)
            "_CFArrayGetValueAtIndex", referenced from:
                _crypto/x509/internal/macos.x509_CFArrayGetValueAtIndex_trampoline in libgophernize.a(go.o)
            "_CFDataGetBytePtr", referenced from:
                _crypto/x509/internal/macos.x509_CFDataGetBytePtr_trampoline in libgophernize.a(go.o)
            "_CFEqual", referenced from:
                _crypto/x509/internal/macos.x509_CFEqual_trampoline in libgophernize.a(go.o)
            "_CFStringCreateWithBytes", referenced from:
                _crypto/x509/internal/macos.x509_CFStringCreateWithBytes_trampoline in libgophernize.a(go.o)
            "_CFRelease", referenced from:
                _crypto/x509/internal/macos.x509_CFRelease_trampoline in libgophernize.a(go.o)
            "_CFArrayGetCount", referenced from:
                _crypto/x509/internal/macos.x509_CFArrayGetCount_trampoline in libgophernize.a(go.o)
          ld: symbol(s) not found for architecture x86_64
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

btw, It works on GNU LInux.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions