2

I have a project that I'm compiling with GCC 7.3 c++ 17, my project link to 3rd party lib that builds with GCC 7.3 but with c++11. when I'm trying to link the lib I'm getting undefined reference to ec_core::ECPassword::getPlainText[abi:cxx11]() I tried using this question but with no luck. I'm using CMake. If I'm adding to the CMake file

add_definitions(-D_GLIBCXX_USE_CXX11_ABI=1)

and in the code I'm doing this:

#define _GLIBCXX_USE_CXX11_ABI 0
    ec_framework::ConfigRP _ecconfig = m_ecapp->load(path, fileName, "ver_num");
#undef _GLIBCXX_USE_CXX11_ABI

Im gtting the same error and if I'm doing the opesit AS

add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)

I'm getting a lot of undefined references on other functions. and also if I'm surrounding them with

#define _GLIBCXX_USE_CXX11_ABI 1
    function_name;
#undef _GLIBCXX_USE_CXX11_ABI

it's not helping. is there a way to link them together?

yaodav
  • 1,126
  • 12
  • 34
  • That macro only does something useful at the time you include standard library headers, like you do with `add_definitions` – Botje Nov 15 '20 at 20:50
  • @Botje so is there a different way to fix this problome? – yaodav Nov 16 '20 at 13:28
  • Step one is to check whether the third-party actually contains the missing symbol and step two is to verify whether you're actually correctly linking to it. If you know how the library was built exactly, that is also good to know. – Botje Nov 16 '20 at 13:37
  • @Botje this is the output of `nm` command `nm libec-core.so |grep "ECApplication.*load" 000000000006bce0 T _ZN7ec_core13ECApplication4loadERKSsS2_PKc` – yaodav Nov 16 '20 at 14:02
  • That means the third-party library is not compiled with the cxx11 ABI. Presumably your application is? You should recompile the library *with* cxx11 support or your application *without* cxx11, and preferably with the same compiler version. – Botje Nov 16 '20 at 14:10
  • @Botje how do you can tell that the lib compiled with or without the cxx11 ABI? – yaodav Nov 16 '20 at 14:12
  • Because "Ss" in the mangled symbol name is an abbreviation for `std::string` in the old ABI. With `-D_GLIBCXX_USE_CXX11_ABI=1` I get `_ZN7ec_core13ECApplicationL4loadERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_PKc` instead. – Botje Nov 16 '20 at 14:29
  • @Botje so i need to build my project with `add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)`? – yaodav Nov 16 '20 at 14:38
  • or recompile the library with the CXX11 ABI, yes. You cannot mix both in one application and I expect you link with other libraries that *do* use the CXX11 ABI. – Botje Nov 16 '20 at 14:39
  • @Botje I change the macro and now Im getitng aa lot of `undefined reference` on other fucntion `undefined reference` to `md_framework::Config::getAttrValue(char const*) const'` i run the `nm` command again and this is the output `000000000005c6e0 T _ZNK12ec_framework6Config12getAttrValueEPKc 000000000005c7a0 T _ZNK12ec_framework6Config12getAttrValueEPKcS2_ 000000000005af30 T _ZNK12ec_framework6Config12getAttrValueERKSs 000000000005ae10 T _ZNK12ec_framework6Config12getAttrValueERKSsS2_ ` – yaodav Nov 16 '20 at 15:01
  • md_framework != ec_framework. Please ensure you are linking to a library that contains the correct symbol . – Botje Nov 16 '20 at 15:03
  • @Botje last night I got the new lib with c++ 11 ABI and it works, thank you very much. writ it as an answer and I will accept it. – yaodav Nov 22 '20 at 09:02

0 Answers0