Error compile: ld: symbol(s) not found for architecture x86_64 conda
1、报错
GO111MODULE=on go build -tags codes -o bin/tinykv-server kv/main.go
# runtime/cgo
ld: warning: ignoring file /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.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/MacOSX.sdk/usr/lib/libpthread.tbd
ld: warning: ignoring file /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.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/MacOSX.sdk/usr/lib/libSystem.tbd
Undefined symbols for architecture x86_64:
"___stack_chk_fail", referenced from:
_x_cgo_init in _x004.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)
make: *** [kv] Error 2
2、问题 && 解决
> cat ~/.bash_profile 127 ↵
# >>> conda init >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$(CONDA_REPORT_ERRORS=false '/Users/lulu/anaconda3/bin/conda' shell.bash hook 2> /dev/null)"
if [ $? -eq 0 ]; then
\eval "$__conda_setup"
else
if [ -f "/Users/lulu/anaconda3/etc/profile.d/conda.sh" ]; then
. "/Users/lulu/anaconda3/etc/profile.d/conda.sh"
CONDA_CHANGEPS1=false conda activate base
else
\export PATH="/Users/lulu/anaconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda init <<<
> which clang
/Users/username/anaconda3/bin/clang
# 此时的clang是在/Users/username/anaconda3/bin/clang这个目录,环境问题导致
> export CC=/usr/bin/clang
# 临时解决~~将go的CC设置成/usr/bin/clang
> go env CC
/usr/bin/clang
> go build **.go
# success