Install TA-LIB with clang compiler error: command 'x86_64-linux-gnu-gcc' failed: No such file or directory

Install TA-LIB with clang compiler error: command 'x86_64-linux-gnu-gcc' failed: No such file or directory

设置

在 AWS 上使用 ubuntu20 t2.micro

sudo apt-get install python3 clang # Make sure gcc is not used instead of clang

安装 TA-LIB C 库。

wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz
tar zxvf
cd ta-lib
./configure --prefix=/usr
make
sudo make install

安装 pip、python3-dev、python3.9-dev 和 python TA-LIB 包装器

sudo curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
sudo CC=clang python3.9 get-pip.py 
sudo apt-get install python3-dev python3.9-dev
sudo CC=clang python3.9 -m pip install TA-LIB

错误

我收到上一条命令的错误输出

$ CC=clang python3.9 -m pip install TA-LIB
Defaulting to user installation because normal site-packages is not writeable
Collecting TA-LIB
  Using cached TA-Lib-0.4.24.tar.gz (269 kB)
  Preparing metadata (setup.py) ... done
Requirement already satisfied: numpy in ./.local/lib/python3.9/site-packages (from TA-LIB) (1.22.1)
Building wheels for collected packages: TA-LIB
  Building wheel for TA-LIB (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /usr/bin/python3.9 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-btb1_xuf/ta-lib_0aa6c802ac734a0dbb58621b44b06499/setup.py'"'"'; __file__='"'"'/tmp/pip-install-btb1_xuf/ta-lib_0aa6c802ac734a0dbb58621b44b06499/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-ay3k6nzj
       cwd: /tmp/pip-install-btb1_xuf/ta-lib_0aa6c802ac734a0dbb58621b44b06499/
  Complete output (61 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-3.9
  creating build/lib.linux-x86_64-3.9/talib
  copying talib/abstract.py -> build/lib.linux-x86_64-3.9/talib
  copying talib/stream.py -> build/lib.linux-x86_64-3.9/talib
  copying talib/test_stream.py -> build/lib.linux-x86_64-3.9/talib
  copying talib/test_polars.py -> build/lib.linux-x86_64-3.9/talib
  copying talib/test_pandas.py -> build/lib.linux-x86_64-3.9/talib
  copying talib/test_abstract.py -> build/lib.linux-x86_64-3.9/talib
  copying talib/test_func.py -> build/lib.linux-x86_64-3.9/talib
  copying talib/test_data.py -> build/lib.linux-x86_64-3.9/talib
  copying talib/deprecated.py -> build/lib.linux-x86_64-3.9/talib
  copying talib/__init__.py -> build/lib.linux-x86_64-3.9/talib
  running build_ext
  building 'talib._ta_lib' extension
  creating build/temp.linux-x86_64-3.9
  creating build/temp.linux-x86_64-3.9/talib
  clang -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include -I/usr/local/include -I/opt/include -I/opt/local/include -I/opt/homebrew/include -I/opt/homebrew/opt/ta-lib/include -I/home/ubuntu/.local/lib/python3.9/site-packages/numpy/core/include -I/usr/include/python3.9 -c talib/_ta_lib.c -o build/temp.linux-x86_64-3.9/talib/_ta_lib.o
  In file included from talib/_ta_lib.c:689:
  In file included from /home/ubuntu/.local/lib/python3.9/site-packages/numpy/core/include/numpy/arrayobject.h:5:
  In file included from /home/ubuntu/.local/lib/python3.9/site-packages/numpy/core/include/numpy/ndarrayobject.h:12:
  In file included from /home/ubuntu/.local/lib/python3.9/site-packages/numpy/core/include/numpy/ndarraytypes.h:1960:
  /home/ubuntu/.local/lib/python3.9/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: "Using deprecated NumPy API, disable it with "          "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-W#warnings]
  #warning "Using deprecated NumPy API, disable it with " \
   ^
  talib/_ta_lib.c:38706:103: warning: passing 'TA_FuncInfo **' (aka 'struct TA_FuncInfo **') to parameter of type 'const TA_FuncInfo **' (aka 'const struct TA_FuncInfo **') discards qualifiers in nested pointer types [-Wincompatible-pointer-types-discards-qualifiers]
    __pyx_v_retCode = TA_GetFuncInfo(__pyx_f_5talib_7_ta_lib___ta_getFuncHandle(__pyx_v_function_name), (&__pyx_v_info));
                                                                                                        ^~~~~~~~~~~~~~~
  /usr/local/include/ta-lib/ta_abstract.h:211:48: note: passing argument to parameter 'funcInfo' here
                             const TA_FuncInfo **funcInfo );
                                                 ^
  talib/_ta_lib.c:38977:126: warning: passing 'TA_InputParameterInfo **' (aka 'struct TA_InputParameterInfo **') to parameter of type 'const TA_InputParameterInfo **' (aka 'const struct TA_InputParameterInfo **') discards qualifiers in nested pointer types [-Wincompatible-pointer-types-discards-qualifiers]
    __pyx_v_retCode = TA_GetInputParameterInfo(__pyx_f_5talib_7_ta_lib___ta_getFuncHandle(__pyx_v_function_name), __pyx_v_idx, (&__pyx_v_info));
                                                                                                                               ^~~~~~~~~~~~~~~
  /usr/local/include/ta-lib/ta_abstract.h:442:68: note: passing argument to parameter 'info' here
                                       const TA_InputParameterInfo **info );
                                                                     ^
  talib/_ta_lib.c:39227:129: warning: passing 'TA_OptInputParameterInfo **' (aka 'struct TA_OptInputParameterInfo **') to parameter of type 'const TA_OptInputParameterInfo **' (aka 'const struct TA_OptInputParameterInfo **') discards qualifiers in nested pointer types [-Wincompatible-pointer-types-discards-qualifiers]
    __pyx_v_retCode = TA_GetOptInputParameterInfo(__pyx_f_5talib_7_ta_lib___ta_getFuncHandle(__pyx_v_function_name), __pyx_v_idx, (&__pyx_v_info));
                                                                                                                                  ^~~~~~~~~~~~~~~
  /usr/local/include/ta-lib/ta_abstract.h:446:74: note: passing argument to parameter 'info' here
                                          const TA_OptInputParameterInfo **info );
                                                                           ^
  talib/_ta_lib.c:39473:127: warning: passing 'TA_OutputParameterInfo **' (aka 'struct TA_OutputParameterInfo **') to parameter of type 'const TA_OutputParameterInfo **' (aka 'const struct TA_OutputParameterInfo **') discards qualifiers in nested pointer types [-Wincompatible-pointer-types-discards-qualifiers]
    __pyx_v_retCode = TA_GetOutputParameterInfo(__pyx_f_5talib_7_ta_lib___ta_getFuncHandle(__pyx_v_function_name), __pyx_v_idx, (&__pyx_v_info));
                                                                                                                                ^~~~~~~~~~~~~~~
  /usr/local/include/ta-lib/ta_abstract.h:450:70: note: passing argument to parameter 'info' here
                                        const TA_OutputParameterInfo **info );
                                                                       ^
  talib/_ta_lib.c:40072:125: warning: passing 'TA_FuncHandle **' (aka 'unsigned int **') to parameter of type 'const TA_FuncHandle **' (aka 'const unsigned int **') discards qualifiers in nested pointer types [-Wincompatible-pointer-types-discards-qualifiers]
    __pyx_t_1 = __pyx_f_5talib_7_ta_lib__ta_check_success(__pyx_n_s_TA_GetFuncHandle, TA_GetFuncHandle(__pyx_v_function_name, (&__pyx_v_handle)), 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 751, __pyx_L1_error)
                                                                                                                              ^~~~~~~~~~~~~~~~~
  /usr/local/include/ta-lib/ta_abstract.h:155:52: note: passing argument to parameter 'handle' here
                               const TA_FuncHandle **handle );
                                                     ^
  6 warnings generated.
  x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -g -fwrapv -O2 -Wl,-Bsymbolic-functions -Wl,-z,relro -g -fwrapv -O2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 build/temp.linux-x86_64-3.9/talib/_ta_lib.o -L/usr/local/lib -L/usr/local/lib64 -L/opt/lib -L/opt/local/lib -L/opt/homebrew/lib -L/opt/homebrew/opt/ta-lib/lib -Wl,--enable-new-dtags,-R/usr/local/lib -Wl,--enable-new-dtags,-R/usr/local/lib64 -Wl,--enable-new-dtags,-R/opt/lib -Wl,--enable-new-dtags,-R/opt/local/lib -Wl,--enable-new-dtags,-R/opt/homebrew/lib -Wl,--enable-new-dtags,-R/opt/homebrew/opt/ta-lib/lib -lta_lib -o build/lib.linux-x86_64-3.9/talib/_ta_lib.cpython-39-x86_64-linux-gnu.so
  error: command 'x86_64-linux-gnu-gcc' failed: No such file or directory
  ----------------------------------------
  ERROR: Failed building wheel for TA-LIB
  Running setup.py clean for TA-LIB
Failed to build TA-LIB
Installing collected packages: TA-LIB
    Running setup.py install for TA-LIB ... error
    ERROR: Command errored out with exit status 1:
     command: /usr/bin/python3.9 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-btb1_xuf/ta-lib_0aa6c802ac734a0dbb58621b44b06499/setup.py'"'"'; __file__='"'"'/tmp/pip-install-btb1_xuf/ta-lib_0aa6c802ac734a0dbb58621b44b06499/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-3qtsugx0/install-record.txt --single-version-externally-managed --user --prefix= --compile --install-headers /home/ubuntu/.local/include/python3.9/TA-LIB
         cwd: /tmp/pip-install-btb1_xuf/ta-lib_0aa6c802ac734a0dbb58621b44b06499/
    Complete output (61 lines):
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.9
    creating build/lib.linux-x86_64-3.9/talib
    copying talib/abstract.py -> build/lib.linux-x86_64-3.9/talib
    copying talib/stream.py -> build/lib.linux-x86_64-3.9/talib
    copying talib/test_stream.py -> build/lib.linux-x86_64-3.9/talib
    copying talib/test_polars.py -> build/lib.linux-x86_64-3.9/talib
    copying talib/test_pandas.py -> build/lib.linux-x86_64-3.9/talib
    copying talib/test_abstract.py -> build/lib.linux-x86_64-3.9/talib
    copying talib/test_func.py -> build/lib.linux-x86_64-3.9/talib
    copying talib/test_data.py -> build/lib.linux-x86_64-3.9/talib
    copying talib/deprecated.py -> build/lib.linux-x86_64-3.9/talib
    copying talib/__init__.py -> build/lib.linux-x86_64-3.9/talib
    running build_ext
    building 'talib._ta_lib' extension
    creating build/temp.linux-x86_64-3.9
    creating build/temp.linux-x86_64-3.9/talib
    clang -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include -I/usr/local/include -I/opt/include -I/opt/local/include -I/opt/homebrew/include -I/opt/homebrew/opt/ta-lib/include -I/home/ubuntu/.local/lib/python3.9/site-packages/numpy/core/include -I/usr/include/python3.9 -c talib/_ta_lib.c -o build/temp.linux-x86_64-3.9/talib/_ta_lib.o
    In file included from talib/_ta_lib.c:689:
    In file included from /home/ubuntu/.local/lib/python3.9/site-packages/numpy/core/include/numpy/arrayobject.h:5:
    In file included from /home/ubuntu/.local/lib/python3.9/site-packages/numpy/core/include/numpy/ndarrayobject.h:12:
    In file included from /home/ubuntu/.local/lib/python3.9/site-packages/numpy/core/include/numpy/ndarraytypes.h:1960:
    /home/ubuntu/.local/lib/python3.9/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: "Using deprecated NumPy API, disable it with "          "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-W#warnings]
    #warning "Using deprecated NumPy API, disable it with " \
     ^
    talib/_ta_lib.c:38706:103: warning: passing 'TA_FuncInfo **' (aka 'struct TA_FuncInfo **') to parameter of type 'const TA_FuncInfo **' (aka 'const struct TA_FuncInfo **') discards qualifiers in nested pointer types [-Wincompatible-pointer-types-discards-qualifiers]
      __pyx_v_retCode = TA_GetFuncInfo(__pyx_f_5talib_7_ta_lib___ta_getFuncHandle(__pyx_v_function_name), (&__pyx_v_info));
                                                                                                          ^~~~~~~~~~~~~~~
    /usr/local/include/ta-lib/ta_abstract.h:211:48: note: passing argument to parameter 'funcInfo' here
                               const TA_FuncInfo **funcInfo );
                                                   ^
    talib/_ta_lib.c:38977:126: warning: passing 'TA_InputParameterInfo **' (aka 'struct TA_InputParameterInfo **') to parameter of type 'const TA_InputParameterInfo **' (aka 'const struct TA_InputParameterInfo **') discards qualifiers in nested pointer types [-Wincompatible-pointer-types-discards-qualifiers]
      __pyx_v_retCode = TA_GetInputParameterInfo(__pyx_f_5talib_7_ta_lib___ta_getFuncHandle(__pyx_v_function_name), __pyx_v_idx, (&__pyx_v_info));
                                                                                                                                 ^~~~~~~~~~~~~~~
    /usr/local/include/ta-lib/ta_abstract.h:442:68: note: passing argument to parameter 'info' here
                                         const TA_InputParameterInfo **info );
                                                                       ^
    talib/_ta_lib.c:39227:129: warning: passing 'TA_OptInputParameterInfo **' (aka 'struct TA_OptInputParameterInfo **') to parameter of type 'const TA_OptInputParameterInfo **' (aka 'const struct TA_OptInputParameterInfo **') discards qualifiers in nested pointer types [-Wincompatible-pointer-types-discards-qualifiers]
      __pyx_v_retCode = TA_GetOptInputParameterInfo(__pyx_f_5talib_7_ta_lib___ta_getFuncHandle(__pyx_v_function_name), __pyx_v_idx, (&__pyx_v_info));
                                                                                                                                    ^~~~~~~~~~~~~~~
    /usr/local/include/ta-lib/ta_abstract.h:446:74: note: passing argument to parameter 'info' here
                                            const TA_OptInputParameterInfo **info );
                                                                             ^
    talib/_ta_lib.c:39473:127: warning: passing 'TA_OutputParameterInfo **' (aka 'struct TA_OutputParameterInfo **') to parameter of type 'const TA_OutputParameterInfo **' (aka 'const struct TA_OutputParameterInfo **') discards qualifiers in nested pointer types [-Wincompatible-pointer-types-discards-qualifiers]
      __pyx_v_retCode = TA_GetOutputParameterInfo(__pyx_f_5talib_7_ta_lib___ta_getFuncHandle(__pyx_v_function_name), __pyx_v_idx, (&__pyx_v_info));
                                                                                                                                  ^~~~~~~~~~~~~~~
    /usr/local/include/ta-lib/ta_abstract.h:450:70: note: passing argument to parameter 'info' here
                                          const TA_OutputParameterInfo **info );
                                                                         ^
    talib/_ta_lib.c:40072:125: warning: passing 'TA_FuncHandle **' (aka 'unsigned int **') to parameter of type 'const TA_FuncHandle **' (aka 'const unsigned int **') discards qualifiers in nested pointer types [-Wincompatible-pointer-types-discards-qualifiers]
      __pyx_t_1 = __pyx_f_5talib_7_ta_lib__ta_check_success(__pyx_n_s_TA_GetFuncHandle, TA_GetFuncHandle(__pyx_v_function_name, (&__pyx_v_handle)), 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 751, __pyx_L1_error)
                                                                                                                                ^~~~~~~~~~~~~~~~~
    /usr/local/include/ta-lib/ta_abstract.h:155:52: note: passing argument to parameter 'handle' here
                                 const TA_FuncHandle **handle );
                                                       ^
    6 warnings generated.
    x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -g -fwrapv -O2 -Wl,-Bsymbolic-functions -Wl,-z,relro -g -fwrapv -O2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 build/temp.linux-x86_64-3.9/talib/_ta_lib.o -L/usr/local/lib -L/usr/local/lib64 -L/opt/lib -L/opt/local/lib -L/opt/homebrew/lib -L/opt/homebrew/opt/ta-lib/lib -Wl,--enable-new-dtags,-R/usr/local/lib -Wl,--enable-new-dtags,-R/usr/local/lib64 -Wl,--enable-new-dtags,-R/opt/lib -Wl,--enable-new-dtags,-R/opt/local/lib -Wl,--enable-new-dtags,-R/opt/homebrew/lib -Wl,--enable-new-dtags,-R/opt/homebrew/opt/ta-lib/lib -lta_lib -o build/lib.linux-x86_64-3.9/talib/_ta_lib.cpython-39-x86_64-linux-gnu.so
    error: command 'x86_64-linux-gnu-gcc' failed: No such file or directory
    ----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python3.9 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-btb1_xuf/ta-lib_0aa6c802ac734a0dbb58621b44b06499/setup.py'"'"'; __file__='"'"'/tmp/pip-install-btb1_xuf/ta-lib_0aa6c802ac734a0dbb58621b44b06499/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-3qtsugx0/install-record.txt --single-version-externally-managed --user --prefix= --compile --install-headers /home/ubuntu/.local/include/python3.9/TA-LIB Check the logs for full command output.

其中最重要的一行看起来像

error: command 'x86_64-linux-gnu-gcc' failed: No such file or directory

当我运行clang++ -v我得到

$ clang++ -v
clang version 10.0.0-4ubuntu1 
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/9
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/9
Candidate multilib: .;@m64
Selected multilib: .;@m64

尝试过的解决方案

我已经安装并尝试安装这些包来尝试修复它: python3-clang-9autoconflibtoolpkg-config

安装 build-essential 不是一个选项,因为它会安装 gcc 而我正在尝试使用 clang 而不是 gcc

设置变量 CC 是不够的 - 您还需要设置 LDSHARED。您的 pip install 命令应该如下所示:

sudo CC=clang LDSHARED=clang python3.9 -m pip install TA-LIB

或者也许:

sudo LDSHARED="clang -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions" \
CC="clang -pthread" python3.9 -m pip install TA-LIB

编辑:

详细说明一下,当你 pip 安装 TA-LIB 时,它会做很多事情,,然后 运行s setup.py 和一些选项:

  • setup.py install
  • setup.py build
  • setup.py install_lib
  • setup.py build_py
  • setup.py build_ext

我们关心最后一个,setup.py build_ext。这将 distutils.build_ext 中包含的 运行 逻辑,特别是它构造一个编译器对象并对其进行自定义:

from distutils.sysconfig import customize_compiler, get_python_version

class build_ext(Command):
    def run(self):
        ...

        self.compiler = new_compiler(compiler=self.compiler,
                                     verbose=self.verbose,
                                     dry_run=self.dry_run,
                                     force=self.force)
        customize_compiler(self.compiler)

如果我们窥视 distutils.sysconfig,并查看 customize_compiler(),我们将看到在哪里检查一些环境变量,并相应地配置编译器对象:

if 'CC' in os.environ:
    newcc = os.environ['CC']
    if (sys.platform == 'darwin'
            and 'LDSHARED' not in os.environ
            and ldshared.startswith(cc)):
        # On OS X, if CC is overridden, use that as the default
        #       command for LDSHARED as well
        ldshared = newcc + ldshared[len(cc):]
    cc = newcc
if 'CXX' in os.environ:
    cxx = os.environ['CXX']
if 'LDSHARED' in os.environ:
    ldshared = os.environ['LDSHARED']
if 'CPP' in os.environ:
    cpp = os.environ['CPP']
else:
    cpp = cc + " -E"           # not always
if 'LDFLAGS' in os.environ:
    ldshared = ldshared + ' ' + os.environ['LDFLAGS']
if 'CFLAGS' in os.environ:
    cflags = cflags + ' ' + os.environ['CFLAGS']
    ldshared = ldshared + ' ' + os.environ['CFLAGS']
if 'CPPFLAGS' in os.environ:
    cpp = cpp + ' ' + os.environ['CPPFLAGS']
    cflags = cflags + ' ' + os.environ['CPPFLAGS']
    ldshared = ldshared + ' ' + os.environ['CPPFLAGS']
if 'AR' in os.environ:
    ar = os.environ['AR']
if 'ARFLAGS' in os.environ:
    archiver = ar + ' ' + os.environ['ARFLAGS']
else:
    archiver = ar + ' ' + ar_flags

cc_cmd = cc + ' ' + cflags
compiler.set_executables(
    preprocessor=cpp,
    compiler=cc_cmd,
    compiler_so=cc_cmd + ' ' + ccshared,
    compiler_cxx=cxx,
    linker_so=ldshared,
    linker_exe=cc,
    archiver=archiver)

特别是,我们看到它设置 ldshared,并将其作为 linker_so 传递给编译器(并设置为其中的一个属性)。

distutils.unixcompiler.UnixCCompiler(这里使用的 CCompiler 的子类,之前由 new_compiler() 返回)中,我们找到 link() 的实现,使用这个可执行文件,然后将其生成为一个过程:

if target_desc == CCompiler.EXECUTABLE:
    linker = self.linker_exe[:]
else:
    linker = self.linker_so[:]
...

self.spawn(linker + ld_args)

我们还将找到 compiler/linker/etc 的默认值。

executables = {'preprocessor' : None,
           'compiler'     : ["cc"],
           'compiler_so'  : ["cc"],
           'compiler_cxx' : ["cc"],
           'linker_so'    : ["cc", "-shared"],
           'linker_exe'   : ["cc"],
           'archiver'     : ["ar", "-cr"],
           'ranlib'       : None,
          }

在您的系统上,cc 只是 x86_64-linux-gnu-gcc 的符号链接,因此在我们在环境变量中显式提供链接器覆盖之前,它就是从中获取该值的地方。