问题出现
上周有个python的代码引用了golang的部分代码模块,直接采用gopy将golang代码编译成python能直接调用的so文件,提交代码通过conda build自动打包时报了如下错误
gopy build -vm=python3 -output=out ./sdk
goimports -w sdk.go
go build -buildmode=c-shared -o sdk\_go.so .
python3 build.py
go env CC
python3-config --cflags
python3-config --ldflags
/home/soft/miniconda3/bin/x86\_64-conda\_cos6-linux-gnu-cc sdk.c sdk\_go.so -o \_sdk.so -I/home/soft/miniconda3/include/python3.7m -I/home/soft/miniconda3/include/python3.7m -Wno-unused-result -Wsign-compare -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O3 -ffunction-sections -pipe -fdebug-prefix-map=/tmp/build/80754af9/python\_1553721932202/work=/usr/local/src/conda/python-3.7.3 -fdebug-prefix-map=/home/soft/miniconda3=/usr/local/src/conda-prefix -fuse-linker-plugin -ffat-lto-objects -flto-partition=none -flto -DNDEBUG -fwrapv -O3 -Wall -L/home/soft/miniconda3/lib/python3.7/config-3.7m-x86\_64-linux-gnu -L/home/soft/miniconda3/lib -lpython3.7m -lcrypt -lpthread -ldl -lutil -lrt -lm -Xlinker -export-dynamic -fPIC --shared
cmd had error: exit status 1
output: lto1: fatal error: bytecode stream in file '/home/soft/miniconda3/lib/python3.7/config-3.7m-x86\_64-linux-gnu/libpython3.7m.a' generated with LTO version 6.0 instead of the expected 6.2
compilation terminated.
lto-wrapper: fatal error: /home/soft/miniconda3/bin/x86\_64-conda\_cos6-linux-gnu-cc returned 1 exit status
compilation terminated.
/home/soft/miniconda3/bin/../lib/gcc/x86\_64-conda\_cos6-linux-gnu/7.5.0/../../../../x86\_64-conda\_cos6-linux-gnu/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status
问题分析
遇到这个问题,我先Google了一下,网上也有不少人反馈这个问题,其中Possible problem with LTO on Anaconda 5.0就是conda环境下编译的问题,这个主要是gcc的版本太新,而miniconda3的python3的环境有点老的问题,实际上我们要做的就是降低gcc的版本。当前gcc版本是7.5.0
/home/soft/miniconda3/bin/x86_64-conda_cos6-linux-gnu-cc -v
Reading specs from /home/soft/miniconda3/bin/../lib/gcc/x86_64-conda_cos6-linux-gnu/7.5.0/specs
COLLECT_GCC=/home/soft/miniconda3/bin/x86_64-conda_cos6-linux-gnu-cc
COLLECT_LTO_WRAPPER=/home/soft/miniconda3/bin/../libexec/gcc/x86_64-conda_cos6-linux-gnu/7.5.0/lto-wrapper
Target: x86_64-conda_cos6-linux-gnu
Configured with: /home/conda/feedstock_root/build_artifacts/ctng-compilers_1589464284303/work/.build/x86_64-conda_cos6-linux-gnu/src/gcc/configure --build=x86_64-build_pc-linux-gnu --host=x86_64-build_pc-linux-gnu --target=x86_64-conda_cos6-linux-gnu --prefix=/home/conda/feedstock_root/build_artifacts/ctng-compilers_1589464284303/work/gcc_built --with-sysroot=/home/conda/feedstock_root/build_artifacts/ctng-compilers_1589464284303/work/gcc_built/x86_64-conda_cos6-linux-gnu/sysroot --enable-languages=c,c++,fortran,objc,obj-c++ --with-pkgversion='crosstool-NG 1.24.0.123_1667d2b' --enable-__cxa_atexit --disable-libmudflap --enable-libgomp --disable-libssp --enable-libquadmath --enable-libquadmath-support --enable-libsanitizer --enable-libmpx --with-gmp=/home/conda/feedstock_root/build_artifacts/ctng-compilers_1589464284303/work/.build/x86_64-conda_cos6-linux-gnu/buildtools --with-mpfr=/home/conda/feedstock_root/build_artifacts/ctng-compilers_1589464284303/work/.build/x86_64-conda_cos6-linux-gnu/buildtools --with-mpc=/home/conda/feedstock_root/build_artifacts/ctng-compilers_1589464284303/work/.build/x86_64-conda_cos6-linux-gnu/buildtools --with-isl=/home/conda/feedstock_root/build_artifacts/ctng-compilers_1589464284303/work/.build/x86_64-conda_cos6-linux-gnu/buildtools --enable-lto --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' --enable-threads=posix --enable-target-optspace --enable-plugin --enable-gold --disable-nls --disable-multilib --with-local-prefix=/home/conda/feedstock_root/build_artifacts/ctng-compilers_1589464284303/work/gcc_built/x86_64-conda_cos6-linux-gnu/sysroot --enable-long-long --enable-default-pie
Thread model: posix
gcc version 7.5.0 (crosstool-NG 1.24.0.123_1667d2b)
我们安装下conda环境下的gcc
conda install -c anaconda gcc_linux-64
安装版本是7.3.0
Collecting package metadata (current_repodata.json): done
Solving environment: done
## Package Plan ##
environment location: /home/soft/miniconda3
added / updated specs:
- gcc_linux-64
The following packages will be downloaded:
package | build
---------------------------|-----------------
binutils_impl_linux-64-2.31.1| h6176602_1 16.5 MB anaconda
binutils_linux-64-2.31.1 | h6176602_9 24 KB anaconda
ca-certificates-2020.1.1 | 0 132 KB anaconda
certifi-2020.4.5.1 | py37_0 159 KB anaconda
conda-4.8.3 | py37_0 3.0 MB anaconda
gcc_impl_linux-64-7.3.0 | habb00fd_1 73.2 MB anaconda
gcc_linux-64-7.3.0 | h553295d_9 25 KB anaconda
openssl-1.1.1g | h7b6447c_0 3.8 MB anaconda
------------------------------------------------------------
Total: 96.8 MB
The following NEW packages will be INSTALLED:
binutils_impl_lin~ anaconda/linux-64::binutils_impl_linux-64-2.31.1-h6176602_1
binutils_linux-64 anaconda/linux-64::binutils_linux-64-2.31.1-h6176602_9
gcc_impl_linux-64 anaconda/linux-64::gcc_impl_linux-64-7.3.0-habb00fd_1
gcc_linux-64 anaconda/linux-64::gcc_linux-64-7.3.0-h553295d_9
The following packages will be UPDATED:
ca-certificates pkgs/main::ca-certificates-2019.5.15-0 --> anaconda::ca-certificates-2020.1.1-0
certifi pkgs/main::certifi-2019.6.16-py37_0 --> anaconda::certifi-2020.4.5.1-py37_0
conda pkgs/main::conda-4.7.10-py37_0 --> anaconda::conda-4.8.3-py37_0
openssl pkgs/main::openssl-1.1.1c-h7b6447c_1 --> anaconda::openssl-1.1.1g-h7b6447c_0
Proceed ([y]/n)? y
Downloading and Extracting Packages
ca-certificates-2020 | 132 KB | ######################################################################################################################################################################## | 100%
gcc_impl_linux-64-7. | 73.2 MB | ######################################################################################################################################################################## | 100%
certifi-2020.4.5.1 | 159 KB | ######################################################################################################################################################################## | 100%
conda-4.8.3 | 3.0 MB | ######################################################################################################################################################################## | 100%
binutils_linux-64-2. | 24 KB | ######################################################################################################################################################################## | 100%
openssl-1.1.1g | 3.8 MB | ######################################################################################################################################################################## | 100%
binutils_impl_linux- | 16.5 MB | ######################################################################################################################################################################## | 100%
gcc_linux-64-7.3.0 | 25 KB | ######################################################################################################################################################################## | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
查看gcc版本
/home/soft/miniconda3/bin/x86_64-conda_cos6-linux-gnu-cc -v
Reading specs from /home/soft/miniconda3/bin/../lib/gcc/x86_64-conda_cos6-linux-gnu/7.3.0/specs
COLLECT_GCC=/home/soft/miniconda3/bin/x86_64-conda_cos6-linux-gnu-cc
COLLECT_LTO_WRAPPER=/home/soft/miniconda3/bin/../libexec/gcc/x86_64-conda_cos6-linux-gnu/7.3.0/lto-wrapper
Target: x86_64-conda_cos6-linux-gnu
Configured with: /home/rdonnelly/mc/conda-bld/compilers_linux-64_1534865402226/work/.build/x86_64-conda_cos6-linux-gnu/src/gcc/configure --build=x86_64-build_pc-linux-gnu --host=x86_64-build_pc-linux-gnu --target=x86_64-conda_cos6-linux-gnu --prefix=/home/rdonnelly/mc/conda-bld/compilers_linux-64_1534865402226/work/gcc_built --with-sysroot=/home/rdonnelly/mc/conda-bld/compilers_linux-64_1534865402226/work/gcc_built/x86_64-conda_cos6-linux-gnu/sysroot --enable-languages=c,c++,fortran,objc,obj-c++ --with-pkgversion='crosstool-NG 1.23.0.449-a04d0' --enable-__cxa_atexit --disable-libmudflap --enable-libgomp --disable-libssp --enable-libquadmath --enable-libquadmath-support --enable-libsanitizer --enable-libmpx --with-gmp=/home/rdonnelly/mc/conda-bld/compilers_linux-64_1534865402226/work/.build/x86_64-conda_cos6-linux-gnu/buildtools --with-mpfr=/home/rdonnelly/mc/conda-bld/compilers_linux-64_1534865402226/work/.build/x86_64-conda_cos6-linux-gnu/buildtools --with-mpc=/home/rdonnelly/mc/conda-bld/compilers_linux-64_1534865402226/work/.build/x86_64-conda_cos6-linux-gnu/buildtools --with-isl=/home/rdonnelly/mc/conda-bld/compilers_linux-64_1534865402226/work/.build/x86_64-conda_cos6-linux-gnu/buildtools --enable-lto --enable-threads=posix --enable-target-optspace --enable-plugin --enable-gold --disable-nls --disable-multilib --with-local-prefix=/home/rdonnelly/mc/conda-bld/compilers_linux-64_1534865402226/work/gcc_built/x86_64-conda_cos6-linux-gnu/sysroot --enable-long-long --enable-default-pie
Thread model: posix
gcc version 7.3.0 (crosstool-NG 1.23.0.449-a04d0)
安装完毕后重新编译,发现解决这个问题。
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。