尝试编译C ++ 17文件系统库;得到“找不到版本”

时间:2019-05-08 12:05:25

标签: c++ linker shared-libraries c++17

我最近安装了gcc 9.1.0,从那时起,我一直在探索它的功能。我最近尝试使用文件系统库编译一个简单程序:

#include <iostream>
#include <filesystem>

int main() {
    for(auto& file : std::filesystem::recursive_directory_iterator("./")) {
        std::cout << file.path() << '\n';
    }
}

程序可以正常编译,但是当我尝试运行可执行文件时,出现错误消息:

./a.out: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version GLIBCXX_3.4.26' not found (required by ./a.out)

编译命令为g++ -std=c++17 file.cpp,当我检查g ++的版本时,它给出了以下信息:

g++ (GCC) 9.1.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

所以我知道版本是正确的。如果我以详细模式运行compile命令,它将为我提供以下信息:

Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/9.1.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --prefix=/usr --disable-multilib --disable-libmpx --with-system-zlib --enable-languages=c,c++,fortran,go,objc,obj-c++
Thread model: posix
gcc version 9.1.0 (GCC) 
COLLECT_GCC_OPTIONS='-std=c++17' '-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/libexec/gcc/x86_64-pc-linux-gnu/9.1.0/cc1plus -quiet -v -imultiarch x86_64-linux-gnu -D_GNU_SOURCE file.cpp -quiet -dumpbase file.cpp -mtune=generic -march=x86-64 -auxbase file -std=c++17 -version -o /tmp/cc86K1JE.s
GNU C++17 (GCC) version 9.1.0 (x86_64-pc-linux-gnu)
    compiled by GNU C version 9.1.0, GMP version 6.1.2, MPFR version 4.0.1, MPC version 1.1.0, isl version none
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../../x86_64-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 .
 /home/sky/lib/quanta
 /usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../../include/c++/9.1.0
 /usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../../include/c++/9.1.0/x86_64-pc-linux-gnu
 /usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../../include/c++/9.1.0/backward
 /usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/include
 /usr/local/include
 /usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/include-fixed
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
GNU C++17 (GCC) version 9.1.0 (x86_64-pc-linux-gnu)
    compiled by GNU C version 9.1.0, GMP version 6.1.2, MPFR version 4.0.1, MPC version 1.1.0, isl version none
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 2d3f10affe83e300339eb88540f78342
COLLECT_GCC_OPTIONS='-std=c++17' '-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 as -v --64 -o /tmp/ccTmtLm7.o /tmp/cc86K1JE.s
GNU assembler version 2.30 (x86_64-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.30
COMPILER_PATH=/usr/libexec/gcc/x86_64-pc-linux-gnu/9.1.0/:/usr/libexec/gcc/x86_64-pc-linux-gnu/9.1.0/:/usr/libexec/gcc/x86_64-pc-linux-gnu/:/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/:/usr/lib/gcc/x86_64-pc-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/:/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-std=c++17' '-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/libexec/gcc/x86_64-pc-linux-gnu/9.1.0/collect2 -plugin /usr/libexec/gcc/x86_64-pc-linux-gnu/9.1.0/liblto_plugin.so -plugin-opt=/usr/libexec/gcc/x86_64-pc-linux-gnu/9.1.0/lto-wrapper -plugin-opt=-fresolution=/tmp/cctpSX0z.res -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 /usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../x86_64-linux-gnu/crt1.o /usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/crtbegin.o -L/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0 -L/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../.. /tmp/ccTmtLm7.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/crtend.o /usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../x86_64-linux-gnu/crtn.o
COLLECT_GCC_OPTIONS='-std=c++17' '-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
sky@sunri

如何正确更新或安装正确的库版本?

0 个答案:

没有答案