C equivalent for __cxa_demangle for gcc?

2.2k Views Asked by At

I have used the following function in the past to demangle c++ symbols it has proved very useful:

char* __cxa_demangle(const char* __mangled_name, char* __output_buffer, size_t* __length, int* __status);

Now I work on a C application that uses gcc, but cannot use __cxa_demangle as it is a C program (it's only available with g++ the C++ compiler), in C++ I would have typically called as follows:

abi::__cxa_demangle(mangled.c_str(), NULL, 0, 0);

Anybody know how to achieve the same in C?

1

There are 1 best solutions below

1
ericcurtin On BEST ANSWER

Answering my own question it's in the comment of the source code:

   *  @note The same demangling functionality is available via
   *  libiberty (@c <libiberty/demangle.h> and @c libiberty.a) in GCC
   *  3.1 and later, but that requires explicit installation (@c
   *  --enable-install-libiberty) and uses a different API, although
   *  the ABI is unchanged.
   */
  char*
  __cxa_demangle(const char* __mangled_name, char* __output_buffer,
         size_t* __length, int* __status);