Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x509 with CGO on OSX #47588

Closed
tcastelly opened this issue Aug 7, 2021 · 2 comments
Closed

x509 with CGO on OSX #47588

tcastelly opened this issue Aug 7, 2021 · 2 comments

Comments

@tcastelly
Copy link

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.

@seankhliao
Copy link
Member

Duplicate of #42459

@seankhliao seankhliao marked this as a duplicate of #42459 Aug 7, 2021
@tcastelly
Copy link
Author

tcastelly commented Aug 8, 2021

Hi,

Is there any workaround?
Thank you very much.

Edit:
Fixed with

.cargo/config

[build]
rustflags = ["-C", "link-args=-framework CoreFoundation -framework Security"]

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants