我遇到一个非常奇怪的行为,我将其提炼为一个非常基本的测试:
#include <string>
#include <filesystem>
int main(void)
{
const std::string name = "foo";
const std::filesystem::path lock_dir = "/tmp";
std::filesystem::path lockfile = lock_dir / name;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我用编译g++ -std=c++17 -Wall -Wextra -Werror -g foo.cpp -o foo。当我运行它时,在添加两个路径的那一行上,我得到了一个std :: bad_alloc异常。这是我在gdb中看到的
#0 __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
#1 0x00007ffff742c801 in __GI_abort () at abort.c:79
#2 0x00007ffff7a8e1f2 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#3 0x00007ffff7a99e36 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#4 0x00007ffff7a99e81 in std::terminate() () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#5 0x00007ffff7a9a0b5 in __cxa_throw () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6 …Run Code Online (Sandbox Code Playgroud) 在标准论文P0092R1中,Howard Hinnant写道:
template <class To, class Rep, class Period,
class = enable_if_t<detail::is_duration<To>{}>>
constexpr
To floor(const duration<Rep, Period>& d)
{
To t = duration_cast<To>(d);
if (t > d)
--t;
return t;
}
Run Code Online (Sandbox Code Playgroud)
这段代码怎么样?问题是,operator--a std::chrono::duration不是constexpr操作.它被定义为:
duration& operator--();
Run Code Online (Sandbox Code Playgroud)
然而,这段代码编译,并在编译时给出正确的答案:
static_assert(floor<hours>(minutes{3}).count() == 0, "”);
Run Code Online (Sandbox Code Playgroud)
那是怎么回事?
假设我有以下本地 gcc, g++ 版本:
$ gcc -v
$ g++ -v
gcc version 6.3.1
Run Code Online (Sandbox Code Playgroud)
与我的编译器版本相比,我不理解以下内容的关系和含义:
这是指什么?
/usr/lib64/libstdc++.so.6
Run Code Online (Sandbox Code Playgroud)
尝试运行二进制文件时出现此错误,这是GLIBCXX_3.4.20指什么?为什么数字以3开头?
/lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found
Run Code Online (Sandbox Code Playgroud)
这是什么?
$ strings /usr/lib64/libstdc++.so.6 | grep GLIBCXX
GLIBCXX_3.4
GLIBCXX_3.4.1
GLIBCXX_3.4.2
GLIBCXX_3.4.3
GLIBCXX_3.4.4
GLIBCXX_3.4.5
GLIBCXX_3.4.6
GLIBCXX_3.4.7
GLIBCXX_3.4.8
GLIBCXX_3.4.9
GLIBCXX_3.4.10
GLIBCXX_3.4.11
GLIBCXX_3.4.12
GLIBCXX_3.4.13
GLIBCXX_3.4.14
GLIBCXX_3.4.15
GLIBCXX_3.4.16
GLIBCXX_3.4.17
GLIBCXX_3.4.18
GLIBCXX_3.4.19
Run Code Online (Sandbox Code Playgroud)
ldd版本怎么样?
ldd --version
ldd (GNU libc) 2.17
Run Code Online (Sandbox Code Playgroud)
我无法将所有这些版本号链接在一起。