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' on Darwin #29597

Closed
Chrisedeluxe opened this issue Jan 7, 2019 · 11 comments
Closed

cmd/go: undefined symbols when linking using 'go get' on Darwin #29597

Chrisedeluxe opened this issue Jan 7, 2019 · 11 comments

Comments

@Chrisedeluxe
Copy link

@Chrisedeluxe Chrisedeluxe commented Jan 7, 2019

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

This comment has been minimized.

Copy link

@julieqiu 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
@bcmills bcmills added the GoCommand label Jan 7, 2019
@bcmills

This comment has been minimized.

Copy link
Member

@bcmills 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 changed the title cmd/go: go get failure cmd/go: undefined symbols when linking using 'go get' on Darwin Jan 7, 2019
@Chrisedeluxe

This comment has been minimized.

Copy link
Author

@Chrisedeluxe Chrisedeluxe commented Jan 7, 2019

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

This comment has been minimized.

Copy link
Contributor

@randall77 randall77 commented Jan 7, 2019

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

This comment has been minimized.

Copy link
Author

@Chrisedeluxe Chrisedeluxe commented Jan 7, 2019

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 Jan 7, 2019
@kwingerden

This comment has been minimized.

Copy link

@kwingerden kwingerden commented Jan 8, 2019

@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

This comment has been minimized.

Copy link

@enahs 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

This comment has been minimized.

Copy link

@PMende 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

This comment has been minimized.

Copy link

@timjonesdev timjonesdev commented Jun 7, 2019

@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

This comment has been minimized.

Copy link

@timjonesdev 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.

@Rjrunner44

This comment has been minimized.

Copy link

@Rjrunner44 Rjrunner44 commented Feb 14, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
9 participants
You can’t perform that action at this time.