首页 > 解决方案 > 错误:“_GLIBCXX_TXN_SAFE_DYN”没有命名类型

问题描述

我正在尝试编译一些我在另一台运行 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.
};

标签: c++exceptionc++14clionlibstdc++

解决方案


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

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


推荐阅读