【问题标题】:error: '_GLIBCXX_TXN_SAFE_DYN' does not name a type错误:“_GLIBCXX_TXN_SAFE_DYN”没有命名类型
【发布时间】:2019-07-06 02:58:54
【问题描述】:

我正在尝试编译一些我在另一台运行 CentOS 的机器上编写的 c++ 代码。我正在尝试在 Ubuntu 16.04 中编译,尽管具有相同版本的 gcc (4.8) 和 clion (2018.3),但代码无法正确编译。错误之一是:

error: '_GLIBCXX_TXN_SAFE_DYN' does not name a type
  what() const _GLIBCXX_TXN_SAFE_DYN _GLIBCXX_USE_NOEXCEPT {

我在互联网上搜索了这个错误或试图弄清楚 _GLIBCXX_TXN_SAFE_DYN 的含义,但找不到任何东西。代码仍然可以在 CentOS 机器上正确编译。我可能缺少一些依赖或其他东西,但无法弄清楚。

class TestException : public std::exception {
public:
    /*!
     * @brief Default constructor to create a new instance of @c TestException
     *
     * @param what      A description of what might have gone wrong in the test
     * @param file      The file name where the error occurred (i.e. @c __FILE__ )
     * @param function  The function name in which the error occurred (i.e. @c __FUNCTION__ )
     * @param line      The line number where the error occurred. (i.e. @c__LINE__ )
     */
    TestException(const std::string what, const std::string file, const std::string function, const int line) {
        std::stringstream s;
        s << "TestException in file \"" << file << "\" in function \"" << function << "\" at line " << line
                << ": " << what;
        _msg = s.str();

    }

    //! @brief Return the error message as a string for use in error messages or tracing
    virtual const char*
    what() const _GLIBCXX_TXN_SAFE_DYN _GLIBCXX_USE_NOEXCEPT {
        return _msg.c_str();
    }
private:
    std::string _msg;  //!< @brief The formatted message string.
};

【问题讨论】:

  • 您为什么要使用像_GLIBCXX_TXN_SAFE_DYN 这样的非标准(坦率地说是库内部)符号?谁告诉你他们的,或者你从哪里读到他们的?
  • 其实是别人写的,之前没有给我任何问题,所以我没有更改它们。坦率地说,我不理解他们,这就是为什么我决定不惹他们。
  • 我检查了它工作的系统,并且 g++ 位于不同的位置。 g++ 版本的输出显示它是“g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-28)”。与位于 /usr/bin/g++ 的版本相同。我会在一两天内从编写该代码的开发人员那里得到解释,并希望在这里发布答案。

标签: c++ exception c++14 clion libstdc++


【解决方案1】:

使用 C++ 7.4.0 编译器或更新版本。我对使用 GNU 5.5.0 的客户也有同样的经历。 至少这对我们有用。

-- C 编译器标识为 GNU 7.4.0 -- CXX 编译器标识为 GNU 7.4.0

【讨论】:

    猜你喜欢
    • 2011-12-10
    • 2013-09-09
    • 2015-12-01
    • 2014-12-16
    • 2016-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多