'multiple definition of `std::logic_error::logic_error(std::logic_error const&)
I am cross-compiling a windows application from my Linux host machine and I am getting a linking error of multiple definitions between two files in the std!
/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
in stdexcept:113 I found the definition of the following class
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
};
These are my build flags
-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
Solution 1:[1]
Building the code with CXX_FLAGS += -D_GLIBCXX_DEFINE_STDEXCEPT_COPY_OPS
solved the issue.
by looking at the symbols of test.o using nm -C test.o
, I found that the copy constructor was defined and had an address mentioned next to it, I made an assumption that the compiler automatically created the copy constructor for me as it didn't find its prototype in the class declaration because of #if _GLIBCXX_USE_CXX11_ABI || _GLIBCXX_DEFINE_STDEXCEPT_COPY_OPS
and that's why by defining _GLIBCXX_DEFINE_STDEXCEPT_COPY_OPS
the complier would know that its implemented somewhere else so don't create it!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Andrew Ahmos |