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

cmd/go: undefined symbols when linking using 'go get' with Anaconda C toolchain on Darwin #29597

Closed
Chrisedeluxe opened this issue Jan 7, 2019 · 11 comments
Labels
FrozenDueToAge GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Darwin WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@Chrisedeluxe
Copy link

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

go version go1.11.4 darwin/amd64

Does this issue reproduce with the latest release?

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

go env Output
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/chris/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/chris/desktop/development/go/go-workspace"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="x86_64-apple-darwin13.4.0-clang"
CXX="x86_64-apple-darwin13.4.0-clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/9l/wwkk_jds2jd3y3zlqmr8nbkw0000gn/T/go-build014894980=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

command:
go get github.com/kovetskiy/zabbixctl

What did you expect to see?

Successful compile of the tool

What did you see instead?

output:

runtime/cgo

ld: warning: ld: warning: ignoring file /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/lib/libpthread.tbd, file was built for unsupported file format ( 0x2D 0x2D 0x2D 0x20 0x21 0x74 0x61 0x70 0x69 0x2D 0x74 0x62 0x64 0x2D 0x76 0x33 ) which is not the architecture being linked (x86_64): /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/lib/libpthread.tbd
ignoring file /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/lib/libSystem.tbd, file was built for unsupported file format ( 0x2D 0x2D 0x2D 0x20 0x21 0x74 0x61 0x70 0x69 0x2D 0x74 0x62 0x64 0x2D 0x76 0x33 ) which is not the architecture being linked (x86_64): /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/lib/libSystem.tbd
Undefined symbols for architecture x86_64:
"___stack_chk_fail", referenced from:
_x_cgo_init in _x004.o
__cgo_sys_thread_start in _x004.o
"___stack_chk_guard", referenced from:
_x_cgo_init in _x004.o
__cgo_sys_thread_start in _x004.o
"___stderrp", referenced from:
__cgo_sys_thread_start in _x004.o
_x_cgo_sys_thread_create in _x005.o
_x_cgo_thread_start in _x008.o
"_abort", referenced from:
__cgo_sys_thread_start in _x004.o
_x_cgo_sys_thread_create in _x005.o
_x_cgo_thread_start in _x008.o
"_fprintf", referenced from:
__cgo_sys_thread_start in _x004.o
_x_cgo_sys_thread_create in _x005.o
"_free", referenced from:
_threadentry in _x004.o
"_fwrite", referenced from:
_x_cgo_thread_start in _x008.o
"_malloc", referenced from:
_x_cgo_thread_start in _x008.o
"_nanosleep", referenced from:
_x_cgo_sys_thread_create in _x005.o
__cgo_try_pthread_create in _x005.o
"_pthread_attr_destroy", referenced from:
_x_cgo_init in _x004.o
"_pthread_attr_getstacksize", referenced from:
_x_cgo_init in _x004.o
__cgo_sys_thread_start in _x004.o
"_pthread_attr_init", referenced from:
_x_cgo_init in _x004.o
__cgo_sys_thread_start in _x004.o
"_pthread_cond_broadcast", referenced from:
_x_cgo_notify_runtime_init_done in _x005.o
"_pthread_cond_wait", referenced from:
__cgo_wait_runtime_init_done in _x005.o
"_pthread_create", referenced from:
_x_cgo_sys_thread_create in _x005.o
__cgo_try_pthread_create in _x005.o
(maybe you meant: __cgo_try_pthread_create)
"_pthread_detach", referenced from:
_x_cgo_sys_thread_create in _x005.o
__cgo_try_pthread_create in _x005.o
"_pthread_mutex_lock", referenced from:
__cgo_wait_runtime_init_done in _x005.o
_x_cgo_notify_runtime_init_done in _x005.o
_x_cgo_set_context_function in _x005.o
__cgo_get_context_function in _x005.o
"_pthread_mutex_unlock", referenced from:
__cgo_wait_runtime_init_done in _x005.o
_x_cgo_notify_runtime_init_done in _x005.o
_x_cgo_set_context_function in _x005.o
__cgo_get_context_function in _x005.o
"_pthread_sigmask", referenced from:
__cgo_sys_thread_start in _x004.o
"_setenv", referenced from:
_x_cgo_setenv in _x006.o
(maybe you meant: _x_cgo_setenv)
"_strerror", referenced from:
__cgo_sys_thread_start in _x004.o
_x_cgo_sys_thread_create in _x005.o
"_unsetenv", referenced from:
_x_cgo_unsetenv in _x006.o
(maybe you meant: _x_cgo_unsetenv)
ld: symbol(s) not found for architecture x86_64
clang-4.0: error: linker command failed with exit code 1 (use -v to see invocation)

@julieqiu
Copy link
Member

julieqiu commented Jan 7, 2019

I just tried running the command and wasn't able to reproduce the error. @bcmills would you mind checking out the issue?

@julieqiu julieqiu changed the title go get failure cmd/go: go get failure Jan 7, 2019
@julieqiu julieqiu added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jan 7, 2019
@bcmills bcmills added the GoCommand cmd/go label Jan 7, 2019
@bcmills
Copy link
Contributor

bcmills commented Jan 7, 2019

I'm also unable to reproduce the error (on macOS 10.12, which is the newest version I have readily available).

From the error message, something may be wrong with your Xcode installation. go with CGO_ENABLED=1 needs to be able to link against libpthread, and it looks like yours is corrupted somehow.

Could you try removing and reinstalling Xcode and see if you can still reproduce the error?

Gos-Mac-89:workdir gopher$ CC=clang go1.11.4 env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/gopher/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/gopher"
GOPROXY=""
GORACE=""
GOROOT="/Users/gopher/sdk/go1.11.4"
GOTMPDIR=""
GOTOOLDIR="/Users/gopher/sdk/go1.11.4/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/dx/k53rs1s93538b4x20g46cj_w0000gn/T/go-build278514159=/tmp/go-build -gno-record-gcc-switches -fno-common"

Gos-Mac-89:workdir gopher$ CC=clang go1.11.4 get github.com/kovetskiy/zabbixctl

Gos-Mac-89:workdir gopher$

@bcmills bcmills added OS-Darwin WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Jan 7, 2019
@bcmills bcmills changed the title cmd/go: go get failure cmd/go: undefined symbols when linking using 'go get' on Darwin Jan 7, 2019
@Chrisedeluxe
Copy link
Author

tried to remove Xcode and reinstalled it but the same error occurred:

go get github.com/kovetskiy/zabbixctl

runtime/cgo

ld: warning: ignoring file /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/lib/libSystem.tbd, file was built for unsupported file format ( 0x2D 0x2D 0x2D 0x20 0x21 0x74 0x61 0x70 0x69 0x2D 0x74 0x62 0x64 0x2D 0x76 0x33 ) which is not the architecture being linked (x86_64): /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/lib/libSystem.tbd
ld: warning: ignoring file /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/lib/libpthread.tbd, file was built for unsupported file format ( 0x2D 0x2D 0x2D 0x20 0x21 0x74 0x61 0x70 0x69 0x2D 0x74 0x62 0x64 0x2D 0x76 0x33 ) which is not the architecture being linked (x86_64): /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/lib/libpthread.tbd
Undefined symbols for architecture x86_64:
"___stack_chk_fail", referenced from:
_x_cgo_init in _x004.o
__cgo_sys_thread_start in _x004.o
"___stack_chk_guard", referenced from:
_x_cgo_init in _x004.o
__cgo_sys_thread_start in _x004.o
"___stderrp", referenced from:
__cgo_sys_thread_start in _x004.o
_x_cgo_sys_thread_create in _x005.o
_x_cgo_thread_start in _x008.o
"_abort", referenced from:
__cgo_sys_thread_start in _x004.o
_x_cgo_sys_thread_create in _x005.o
_x_cgo_thread_start in _x008.o
"_fprintf", referenced from:
__cgo_sys_thread_start in _x004.o
_x_cgo_sys_thread_create in _x005.o
"_free", referenced from:
_threadentry in _x004.o
"_fwrite", referenced from:
_x_cgo_thread_start in _x008.o
"_malloc", referenced from:
_x_cgo_thread_start in _x008.o
"_nanosleep", referenced from:
_x_cgo_sys_thread_create in _x005.o
__cgo_try_pthread_create in _x005.o
"_pthread_attr_destroy", referenced from:
_x_cgo_init in _x004.o
"_pthread_attr_getstacksize", referenced from:
_x_cgo_init in _x004.o
__cgo_sys_thread_start in _x004.o
"_pthread_attr_init", referenced from:
_x_cgo_init in _x004.o
__cgo_sys_thread_start in _x004.o
"_pthread_cond_broadcast", referenced from:
_x_cgo_notify_runtime_init_done in _x005.o
"_pthread_cond_wait", referenced from:
__cgo_wait_runtime_init_done in _x005.o
"_pthread_create", referenced from:
_x_cgo_sys_thread_create in _x005.o
__cgo_try_pthread_create in _x005.o
(maybe you meant: __cgo_try_pthread_create)
"_pthread_detach", referenced from:
_x_cgo_sys_thread_create in _x005.o
__cgo_try_pthread_create in _x005.o
"_pthread_mutex_lock", referenced from:
__cgo_wait_runtime_init_done in _x005.o
_x_cgo_notify_runtime_init_done in _x005.o
_x_cgo_set_context_function in _x005.o
__cgo_get_context_function in _x005.o
"_pthread_mutex_unlock", referenced from:
__cgo_wait_runtime_init_done in _x005.o
_x_cgo_notify_runtime_init_done in _x005.o
_x_cgo_set_context_function in _x005.o
__cgo_get_context_function in _x005.o
"_pthread_sigmask", referenced from:
__cgo_sys_thread_start in _x004.o
"_setenv", referenced from:
_x_cgo_setenv in _x006.o
(maybe you meant: _x_cgo_setenv)
"_strerror", referenced from:
__cgo_sys_thread_start in _x004.o
_x_cgo_sys_thread_create in _x005.o
"_unsetenv", referenced from:
_x_cgo_unsetenv in _x006.o
(maybe you meant: _x_cgo_unsetenv)
ld: symbol(s) not found for architecture x86_64
clang-4.0: error: linker command failed with exit code 1 (use -v to see invocation)

go env:

go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/chris/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/chris/desktop/development/go/go-workspace"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="x86_64-apple-darwin13.4.0-clang"
CXX="x86_64-apple-darwin13.4.0-clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/9l/wwkk_jds2jd3y3zlqmr8nbkw0000gn/T/go-build779217636=/tmp/go-build -gno-record-gcc-switches -fno-common"

@randall77
Copy link
Contributor

libSystem.tbd looks bad. Web searches for this file indicate it is a text file describing the exported symbols of libSystem.dylib, not the actual dylib itself. I'm not sure why the linker is reaching for this file as if it was something that could be linked.

@Chrisedeluxe
Copy link
Author

I found the problem. There was another clang installation in my anaconda3 folder. Once I reinstalled it everything worked fine.

thank you all :)

@bcmills bcmills closed this as completed Jan 7, 2019
@kwingerden
Copy link

@Chrisedeluxe Thanks! I recently installed Anaconda for another project, switched back to my Go project, which was now exhibiting this same behavior. You saved me a ton of time because I am sure I would have wasted a lot of time trying to figure this out. Thanks again!

@enahs
Copy link

enahs commented May 17, 2019

I found the problem. There was another clang installation in my anaconda3 folder. Once I reinstalled it everything worked fine.

thank you all :)

Could you be a bit more prescriptive about the steps you took here? I tried copying a different clang (from /usr/bin) and it didn't work. Thanks.

@PMende
Copy link

PMende commented Jun 3, 2019

It would also be helpful for me to hear what was done to resolve the problem. I'm also having these issues, and can't even run go get golang.org/x/tools/cmd/godoc without these undefined symbols errors.

@timjonesdev
Copy link

@Chrisedeluxe Thanks! I recently installed Anaconda for another project, switched back to my Go project, which was now exhibiting this same behavior. You saved me a ton of time because I am sure I would have wasted a lot of time trying to figure this out. Thanks again!

I have the same issue, where I recently installed Anaconda. Can you provide the specific steps you took to correct the problem?

@timjonesdev
Copy link

timjonesdev commented Jun 7, 2019

I found this question:
https://superuser.com/questions/1436104/latest-anaconda-conflicts-with-xcode

This pointed me toward my .bash_profile to see the following added by Anaconda:

# >>> conda init >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$(CONDA_REPORT_ERRORS=false '/Users/{user}/anaconda3/bin/conda' shell.bash hook 2> /dev/null)"
if [ $? -eq 0 ]; then
    \eval "$__conda_setup"
else
    if [ -f "/Users/{user}/anaconda3/etc/profile.d/conda.sh" ]; then
        . "/Users/{user}/anaconda3/etc/profile.d/conda.sh"
        CONDA_CHANGEPS1=false conda activate base
    else
        \export PATH="/Users/{user}/anaconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda init <<<

I commented this out, and my Go builds work again. This is a temporary fix, but gets me back on my merry Go dev way for now.

@adivated
Copy link

note. i also had to restore $CC back to a proper value to resolve this. Anaconda is setting it to x86_64-apple-darwin13.4.0-clang

@bcmills bcmills changed the title cmd/go: undefined symbols when linking using 'go get' on Darwin cmd/go: undefined symbols when linking using 'go get' with Anaconda C toolchain on Darwin Apr 10, 2020
@golang golang locked and limited conversation to collaborators Apr 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Darwin WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

10 participants