无法在 GCC 8.3.1 中使用 TSDuck 进行编译

Posted

技术标签:

【中文标题】无法在 GCC 8.3.1 中使用 TSDuck 进行编译【英文标题】:Cannot compile with TSDuck in GCC 8.3.1 【发布时间】:2021-08-17 20:25:51 【问题描述】: TSDuck 版本 3.27.2438 GCC 版本 8.3.1 Centos 7.9

我正在尝试针对 TSDuck 编译一些代码(RPM 安装版本 3.27-2438)。我在 UString.h 上收到编译错误。 GCC 似乎对在擦除函数中使用 const_iterator 不满意。据我了解,自 C++11 起就允许这样做,应该在 GCC 8.3.1 中实现。有没有其他人遇到过这个问题?这似乎是一个编译器错误,但我也在 GCC 9.3.1 中尝试过并得到了同样的错误。

错误:

/usr/include/tsduck/tsUString.h:2088:84: error: no matching function for call to ‘ts::UString::erase(std::basic_string<char16_t>::const_iterator&)’
         iterator erase(const_iterator position)  return SuperClass::erase(position); 
                                                                                    ^
In file included from /opt/rh/devtoolset-8/root/usr/include/c++/8/string:52,
                 from /opt/rh/devtoolset-8/root/usr/include/c++/8/stdexcept:39,
                 from /opt/rh/devtoolset-8/root/usr/include/c++/8/array:39,
                 from /opt/rh/devtoolset-8/root/usr/include/c++/8/tuple:39,
                 from /opt/rh/devtoolset-8/root/usr/include/c++/8/bits/unique_ptr.h:37,
                 from /opt/rh/devtoolset-8/root/usr/include/c++/8/memory:80,
                 from /workspaces/ts_reader/src/ts_reader/ts_reader.cpp:4:
/opt/rh/devtoolset-8/root/usr/include/c++/8/bits/basic_string.h:4632:7: note: candidate: ‘std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::erase(std::basic_string<_CharT, _Traits, _Alloc>::size_type, std::basic_string<_CharT, _Traits, _Alloc>::size_type) [with _CharT = char16_t; _Traits = std::char_traits<char16_t>; _Alloc = std::allocator<char16_t>; std::basic_string<_CharT, _Traits, _Alloc>::size_type = long unsigned int]’
       erase(size_type __pos = 0, size_type __n = npos)
       ^~~~~
/opt/rh/devtoolset-8/root/usr/include/c++/8/bits/basic_string.h:4632:7: note:   no known conversion for argument 1 from ‘std::basic_string<char16_t>::const_iterator’ aka ‘__gnu_cxx::__normal_iterator<const char16_t*, std::basic_string<char16_t> >’ to ‘std::basic_string<char16_t>::size_type’ aka ‘long unsigned int’
/opt/rh/devtoolset-8/root/usr/include/c++/8/bits/basic_string.h:4648:7: note: candidate: ‘std::basic_string<_CharT, _Traits, _Alloc>::iterator std::basic_string<_CharT, _Traits, _Alloc>::erase(std::basic_string<_CharT, _Traits, _Alloc>::iterator) [with _CharT = char16_t; _Traits = std::char_traits<char16_t>; _Alloc = std::allocator<char16_t>; std::basic_string<_CharT, _Traits, _Alloc>::iterator = __gnu_cxx::__normal_iterator<char16_t*, std::basic_string<char16_t> >; typename _Alloc::rebind<_CharT>::other::pointer = char16_t*]’
       erase(iterator __position)
       ^~~~~
/opt/rh/devtoolset-8/root/usr/include/c++/8/bits/basic_string.h:4648:7: note:   no known conversion for argument 1 from ‘__normal_iterator<const char16_t*,[...]>’ to ‘__normal_iterator<char16_t*,[...]>’
/opt/rh/devtoolset-8/root/usr/include/c++/8/bits/basic_string.h:4668:7: note: candidate: ‘std::basic_string<_CharT, _Traits, _Alloc>::iterator std::basic_string<_CharT, _Traits, _Alloc>::erase(std::basic_string<_CharT, _Traits, _Alloc>::iterator, std::basic_string<_CharT, _Traits, _Alloc>::iterator) [with _CharT = char16_t; _Traits = std::char_traits<char16_t>; _Alloc = std::allocator<char16_t>; std::basic_string<_CharT, _Traits, _Alloc>::iterator = __gnu_cxx::__normal_iterator<char16_t*, std::basic_string<char16_t> >; typename _Alloc::rebind<_CharT>::other::pointer = char16_t*]’
       erase(iterator __first, iterator __last);
       ^~~~~

【问题讨论】:

请创建一个minimal reproducible example 并显示用于编译代码的确切命令。 Fwiw,当使用ts:UString 并使用std::basic_string&lt;char16_t&gt;::const_iterator (ts::UString::const_iterator) 调用其erase() 成员函数时,我没有收到此编译错误。 【参考方案1】:

检查您使用的是 C++11 ABI。

https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_macros.html

_GLIBCXX_USE_CXX11_ABI

默认定义为值 1。可通过 --disable-libstdcxx-dual-abi 和/或 --with-default-libstdcxx-abi 进行配置。 ABI 变化。当定义为非零值时,库头文件将使用 GCC 5 中引入的符合 C++11 的新 ABI,而不是 GCC 3.4 中引入的旧 ABI。这改变了几个类模板的定义,包括 std:string、std::list 和一些语言环境方面。更多详情请见Dual ABI。

【讨论】:

以上是关于无法在 GCC 8.3.1 中使用 TSDuck 进行编译的主要内容,如果未能解决你的问题,请参考以下文章

CMD中无法使用GCC编译C程序

无法在 TDM-GCC 的 typeid 中使用 declval

无法在 gcc 中执行基于配置文件的优化 (PBO)

在 VS 代码中使用 gcc 无法看到 std::vector 的元素

无法使用 gcc 在 Linux 中编译任何 c++ 程序,出现一些奇怪的错误 [重复]

无法使用 MSMPI 和 GCC 编译程序