1

这与配置错误有关,但这是一台纯粹通过 miniconda/conda-forge 安装的全新计算机,因此它应该可以工作。

我的 miniconda 配置非常简单:conda-forge是除默认值 ( ~/.condarc) 之外的唯一通道:

changeps1: false
channels:
  - conda-forge
  - defaults

它是最新的 ( conda update --all)。

GNU C、C++ 和 Fortran 编译器已通过post-5.0 编译器环境安装。以下是以下列表conda list linux

# packages in environment at /home/jpivarski/miniconda3:
#
# Name                    Version                   Build  Channel
binutils_impl_linux-64    2.36.1               h193b22a_2    conda-forge
binutils_linux-64         2.36                hf3e587d_33    conda-forge
gcc_impl_linux-64         9.3.0               h6df7d76_17  
gcc_linux-64              9.3.0               hf25ea35_33    conda-forge
gfortran_impl_linux-64    9.3.0               hc4a2995_19    conda-forge
gfortran_linux-64         9.3.0               hdc58fab_33    conda-forge
gxx_impl_linux-64         9.3.0               hbdd7822_17  
gxx_linux-64              9.3.0               h3fbe746_33    conda-forge
kernel-headers_linux-64   2.6.32              he073ed8_14    conda-forge
ld_impl_linux-64          2.36.1               hea4e1c9_2    conda-forge
libgcc-devel_linux-64     9.3.0               hb95220a_17  
libstdcxx-devel_linux-64  9.3.0               hf0c5c8d_17  
sysroot_linux-64          2.12                he073ed8_14    conda-forge

conda list compiler

# packages in environment at /home/jpivarski/miniconda3:
#
# Name                    Version                   Build  Channel
c-compiler                1.2.0                h7f98852_0    conda-forge
compilers                 1.2.0                ha770c72_0    conda-forge
cxx-compiler              1.2.0                h4bd325d_0    conda-forge
fortran-compiler          1.2.0                h1990efc_0    conda-forge

conda list binutil

# packages in environment at /home/jpivarski/miniconda3:
#
# Name                    Version                   Build  Channel
binutils                  2.36.1               hdd6e379_2    conda-forge
binutils_impl_linux-64    2.36.1               h193b22a_2    conda-forge
binutils_linux-64         2.36                hf3e587d_33    conda-forge

这是一个 Debian 系统,它带有一个名为gcc-8-baseinstalled 的软件包,

gcc-8-base/stable,now 8.3.0-6 amd64 [installed]

但是那个包没有gcc向路径添加命令,所以它不是用户可见的。此 Debian 位于 Chromebook ( /proc/version) 上的 Crostini VM 中:

Linux version 5.4.119-14943-gff839c7fedcc (chrome-bot@chromeos-ci-legacy-us-east1-d-x32-83-pa8b) (Chromium OS 12.0_pre422132_p20210405-r4 clang version 13.0.0 (/var/tmp/portage/sys-devel/llvm-12.0_pre422132_p20210405-r4/work/llvm-12.0_pre422132_p20210405/clang cd442157cff4aad209ae532cbf031abbe10bc1df)) #1 SMP PREEMPT Wed Jul 28 21:06:01 PDT 2021

现在,有趣的部分。这是可以想象到的最简单的 C++ 程序:

// #include <iostream>

int main(int argc, char** argv) {
  int x = 2 + 4;
  // std::cout << "hello world" << std::endl;
  return 0;
}

(是的,当它不起作用时,我注释掉了“hello world”。)

使用以下任何一种编译它:

g++ tmp.cpp
g++ -std=c++11 tmp.cpp
g++ -std=c++11 -lstdc++ tmp.cpp

产量

/home/jpivarski/miniconda3/bin/../lib/gcc/x86_64-conda-linux-gnu/9.3.0/../../../../x86_64-conda-linux-gnu/bin/ld: /home/jpivarski/miniconda3/bin/../lib/gcc/x86_64-conda-linux-gnu/9.3.0/../../../../x86_64-conda-linux-gnu/lib/../lib/libstdc++.so: undefined reference to `aligned_alloc@GLIBC_2.16'
/home/jpivarski/miniconda3/bin/../lib/gcc/x86_64-conda-linux-gnu/9.3.0/../../../../x86_64-conda-linux-gnu/bin/ld: /home/jpivarski/miniconda3/bin/../lib/gcc/x86_64-conda-linux-gnu/9.3.0/../../../../x86_64-conda-linux-gnu/lib/../lib/libstdc++.so: undefined reference to `clock_gettime@GLIBC_2.17'
collect2: error: ld returned 1 exit status

顺便说一句,与ldd /that/long/path/to/libstdc++.so

./../../x86_64-conda-linux-gnu/lib/../lib/libstdc++.so
        linux-vdso.so.1 (0x00007ffd2e8d1000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007ef64da8e000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007ef64d8cd000)
        /lib64/ld-linux-x86-64.so.2 (0x00007ef64dd92000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007ef64d8b3000)

没有什么是“未找到”。

我可以使用以下命令编译上述程序(带有注释掉的“hello world”)gcc

gcc -std=c++11 tmp.cpp

但如果我把#include <iostream>and放std::cout回去,编译器错误是:

/home/jpivarski/miniconda3/bin/../lib/gcc/x86_64-conda-linux-gnu/9.3.0/../../../../x86_64-conda-linux-gnu/bin/ld: /tmp/cc8BE1Tc.o: warning: relocation against `_ZSt4cout' in read-only section `.text'
/home/jpivarski/miniconda3/bin/../lib/gcc/x86_64-conda-linux-gnu/9.3.0/../../../../x86_64-conda-linux-gnu/bin/ld: /tmp/cc8BE1Tc.o: in function `main':
tmp.cpp:(.text+0x20): undefined reference to `std::cout'
/home/jpivarski/miniconda3/bin/../lib/gcc/x86_64-conda-linux-gnu/9.3.0/../../../../x86_64-conda-linux-gnu/bin/ld: tmp.cpp:(.text+0x25): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/home/jpivarski/miniconda3/bin/../lib/gcc/x86_64-conda-linux-gnu/9.3.0/../../../../x86_64-conda-linux-gnu/bin/ld: tmp.cpp:(.text+0x2f): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
/home/jpivarski/miniconda3/bin/../lib/gcc/x86_64-conda-linux-gnu/9.3.0/../../../../x86_64-conda-linux-gnu/bin/ld: tmp.cpp:(.text+0x3a): undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
/home/jpivarski/miniconda3/bin/../lib/gcc/x86_64-conda-linux-gnu/9.3.0/../../../../x86_64-conda-linux-gnu/bin/ld: /tmp/cc8BE1Tc.o: in function `__static_initialization_and_destruction_0(int, int)':
tmp.cpp:(.text+0x6a): undefined reference to `std::ios_base::Init::Init()'
/home/jpivarski/miniconda3/bin/../lib/gcc/x86_64-conda-linux-gnu/9.3.0/../../../../x86_64-conda-linux-gnu/bin/ld: tmp.cpp:(.text+0x7f): undefined reference to `std::ios_base::Init::~Init()'
/home/jpivarski/miniconda3/bin/../lib/gcc/x86_64-conda-linux-gnu/9.3.0/../../../../x86_64-conda-linux-gnu/bin/ld: warning: creating DT_TEXTREL in a PIE
collect2: error: ld returned 1 exit status

它怎么会如此错误配置,以及如何修复它?这是全新安装。还没有发生什么奇怪的事情。如果这应该是对 conda-forge 的错误报告,我不知道在哪里发布。

4

1 回答 1

2

答:我又从头开始安装了,这次成功了。

由于我不能并排尝试这两个(这是在磁盘空间有限的 Chromebook 上,所以这不是一个选项),我只能根据这次的不同来推测原因:

  1. 我在单个“ ”命令中安装了所有低级gcc_linux-64,gxx_linux-64等和高级compilers, c-compiler,而不是单独的命令。cxx-compilerconda install
  2. 我添加channel_priority: strict到我的~/.condarc配置中。

我没有使用高级compilers包(并让它拉入gcc_linux-64,gxx_linux-64等作为依赖项)的唯一原因是因为我不知道它。在我的第一次安装尝试中,我安装了gcc_linux-64and gxx_linux-64,它将它们添加为可通过CCCXX环境变量访问的可执行文件,但不是在路径 asgccg++. 然后,当我意识到该compilers软件包是为面向用户的gccg++(通过c-compilercxx-compiler)而设计的时,我随后安装了它。这些之间的依赖关系可能存在错误的假设,因为conda install应该使所有这些包彼此一致(尤其是在 之后conda update --all)。这是猜测#1。

第二次尝试也有所不同,因为我channel_priority: strict按照我在 conda-forge 上找到的说明添加了。显然,严格优先级的论据是如此强烈,以至于它将成为 conda 5.0 中的默认值。也许我第一次尝试混合 conda-forge 和默认值?(如果是这样,我不知道为什么我以前从未遇到过这个问题——严格的优先级对我来说是新的,尽管我只使用过两个渠道。)这是猜测 #2,我相信它比猜测更强烈#1。

为了完整起见,我还使用mamba进行了第二次尝试,而不是 conda (有限的 CPU 能力;没有时间等待),尽管我不相信这会有所作为。如果是这样,这对 conda 或 mamba 来说都是个坏消息。

我将把这个问答对留给后代,以防其他人遇到类似这样的问题。(如果这样做,您也许可以添加数据来解决上述歧义。)

于 2021-08-04T00:45:40.420 回答