리눅스 & 안드로이드2018. 8. 13. 10:51

Dual ABI https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html

프로젝트 빌드를 하다가 링크에러가 발생했는데, 전혀 예상하지 못했던 링크 에러라 뭔가 싶었다.


구글신을 통해 에러메시지를 가지고 검색 해 보니, Dual ABI를 알려 주었다.

대략 내용은 이러하다. GCC가 C++11 Comformance를 위해 5.0에서부터 std::string과 std::list를 새로 개발 했는데, std::string과 std::list는 오만데서 엄청 사용하고 있는 놈들이니, 두 버전을 동시에 지원해 줘야해서 define을 하나 추가 했다는 것.

기본은 새로운 구현이 활성화 되어 있고, 끄고 싶으면 _GLIBCXX_USE_CXX11_ABI=0 을 추가해 주어야 한다.


내가 만났던 링크 에러 메시지의 부분을 발췌하면 다음과 같다.


undefined reference to ... (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)

undefined reference to ... std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >[abi:cxx11]

undefined reference to ... [abi:cxx11]

undefined reference to ... (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, ...)

collect2: error: ld returned 1 exit status


문서 상에서는 친절하게(?) 아래와 같이 안내하고 있음.

If you get linker errors about undefined references to symbols that involve types in the std::__cxx11 namespace or the tag [abi:cxx11] then it probably indicates that you are trying to link together object files that were compiled with different values for the _GLIBCXX_USE_CXX11_ABI macro. This commonly happens when linking to a third-party library that was compiled with an older version of GCC. If the third-party library cannot be rebuilt with the new ABI then you will need to recompile your code with the old ABI.


Posted by 세월의돌