Skip to content

cmd/go/internal/work, cmd/cgo: duplicate libobjc library with 2 or more cgo packages with Objective-C #67799

@dmitshur

Description

@dmitshur

Go version

go version go1.22.3 darwin/arm64

Output of go env in your module/workspace

Details
GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/gopher/Library/Caches/go-build'
GOENV='/Users/gopher/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/gopher/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/gopher/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.22.3'
GCCGO='gccgo'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/var/folders/_0/h0671fcn4rgb5pn9c745dx2h0000gn/T/tmp.ElsgkzNn19/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/_0/h0671fcn4rgb5pn9c745dx2h0000gn/T/go-build1736924935=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

Consider a minimal program that involves at least two cgo packages, both of which with Objective-C code:

cd $(mktemp -d)
go mod init test
mkdir p1 p2
echo 'package p1; import "C"' > p1/p1.go
echo 'package p2; import "C"' > p2/p2.go
touch p1/p1.m p2/p2.m
echo 'package main; import (_ "test/p1"; _ "test/p2"); func main() {}' > main.go

I tried to build it on macOS Sonoma 14.5 with Xcode 15.4 without custom flags:

go build

What did you see happen?

A warning is printed:

# test
ld: warning: ignoring duplicate libraries: '-lobjc'

What did you expect to see?

No warning printed.


I believe this is a minified reproduce for an issue like fyne-io/fyne#4502.

The duplicate library outcome for 2+ cgo packages with Objective-C has likely been happening for a while, but what's changed recently is that the new linker in Xcode 15 causes the duplicate library to be printed as a warning unless -ldflags=-extldflags=-Wl,-no_warn_duplicate_libraries is used to disable duplicate library warnings. See [1], [2].

[1]: issue #61229 ("cmd/link: issues with Apple's new linker in Xcode 15 beta")
[2]: https://indiestack.com/2023/10/xcode-15-duplicate-library-linker-warnings/

CC @matloob, @cherrymui.

Metadata

Metadata

Assignees

Labels

GoCommandcmd/goNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.OS-Darwincompiler/runtimeIssues related to the Go compiler and/or runtime.

Type

No type

Projects

Status

Todo

Relationships

None yet

Development

No branches or pull requests

Issue actions