首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >`std::logic_error::logic_error(std::logic_error const&)的多重定义

`std::logic_error::logic_error(std::logic_error const&)的多重定义
EN

Stack Overflow用户
提问于 2022-05-05 22:00:55
回答 1查看 143关注 0票数 0

我正在从我的Linux主机交叉编译一个windows应用程序,并且我得到了std中两个文件之间的多个定义的链接错误!

代码语言:javascript
运行
复制
/usr/lib/gcc/i686-w64-mingw32/7.3-win32/libstdc++.a(cow-stdexcept.o):(.text$_ZNSt11logic_errorC2ERKS_+0x0): multiple definition of `std::logic_error::logic_error(std::logic_error const&)'
/home/user1/work/windows-release/test/test.o:/usr/lib/gcc/i686-w64-mingw32/7.3-win32/include/c++/stdexcept:113: first defined here
collect2: error: ld returned 1 exit status

在stdexcept:113中,我找到了以下类的定义

代码语言:javascript
运行
复制
  class logic_error : public exception
  {
    __cow_string _M_msg;

  public:
    /** Takes a character string describing the error.  */
    explicit
    logic_error(const string& __arg) _GLIBCXX_TXN_SAFE;

#if __cplusplus >= 201103L
    explicit
    logic_error(const char*) _GLIBCXX_TXN_SAFE;
#endif

#if _GLIBCXX_USE_CXX11_ABI || _GLIBCXX_DEFINE_STDEXCEPT_COPY_OPS
    logic_error(const logic_error&) _GLIBCXX_USE_NOEXCEPT;
    logic_error& operator=(const logic_error&) _GLIBCXX_USE_NOEXCEPT;
#endif

    virtual ~logic_error() _GLIBCXX_TXN_SAFE_DYN _GLIBCXX_USE_NOEXCEPT;

    /** Returns a C-style character string describing the general cause of
     *  the current error (the same string passed to the ctor).  */
    virtual const char*
    what() const _GLIBCXX_TXN_SAFE_DYN _GLIBCXX_USE_NOEXCEPT;

# ifdef _GLIBCXX_TM_TS_INTERNAL
    friend void*
    ::_txnal_logic_error_get_msg(void* e);
# endif
  };

这些是我的建筑旗子

代码语言:javascript
运行
复制
-g -Wall -fno-strict-aliasing  -D_WIN32_WINNT=0x0501 -D_GLIBCXX_USE_CXX11_ABI=0 -std=c++11 -Wno-unused-parameter -Wno-deprecated-declarations -Wno-placement-new -Wno-unused-local-typedefs -Wno-deprecated -Wextra -DBOOST_LOG_DYN_LINK -O3  -O -MMD -MP -MT
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-05-18 08:45:35

使用CXX_FLAGS += -D_GLIBCXX_DEFINE_STDEXCEPT_COPY_OPS构建代码解决了这个问题。

通过使用nm -C test.o查看test.o的符号,我发现复制构造函数是定义的,它旁边有一个地址,我假设编译器会自动为我创建复制构造函数,因为由于#if _GLIBCXX_USE_CXX11_ABI || _GLIBCXX_DEFINE_STDEXCEPT_COPY_OPS的存在,编译器在类声明中找不到它的原型,这就是为什么通过定义_GLIBCXX_DEFINE_STDEXCEPT_COPY_OPS,编译器会知道它在其他地方实现了,所以不要创建它!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72134088

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档