Undefined Reference to Mempcy@Glibc_2.14 When Compiling on Linux

Linking against older symbol version in a .so file

Just link memcpy statically - pull memcpy.o out of libc.a ar x /path/to/libc.a memcpy.o (whatever version - memcpy is pretty much a standalone function) and include it in your final link. Note that static linking may complicate licensing issues if your project is distributed to the public and not open-source.

Alternatively, you could simply implement memcpy yourself, though the hand-tuned assembly version in glibc is likely to be more efficient

Note that memcpy@GLIBC_2.2.5 is mapped to memmove (old versions of memcpy consistently copied in a predictable direction, which led to it sometimes being misused when memmove should have been used), and this is the only reason for the version bump - you could simply replace memcpy with memmove in your code for this specific case.

Or you could go to static linking, or you could ensure that all systems on your network have the same or better version than your build machine.

Solving GLIBC errors while trying to compile a ROS package

I am using the ROS system offered by robostack for this.

The ROS package was compiled and linked against GLIBC 2.17 (or newer). It will only work on a system with GLIBC 2.17 (or newer).

I get ldd (GNU libc) 2.12

You are trying to use ROS on a system with GLIBC which is too old.

how to solve this issue?

You have several choices:

  • upgrade your OS to something less ancient (GLIBC-2.17 was released almost 10 years ago)
  • find an ROS package which is compatible with your OS
  • rebuild the ROS package on your system from source (this may be non-trivial if ROS depends on newer GLBC features, or newer compiler)
  • run in a docker container with newer GLIBC

Is it possible to statically link libstdc++ and wrap memcpy?

You need to wrap __wrap_memcpy in extern "C" {}, so that this function is is exported as a C function; otherwise its name will be decorated as a C++ function.
In addition I strongly suggest some additional #ifdef, because this problem only occurs with later compiler versions and only for x64 (the conditions are not totally perfect, so may need to adjust them):

#if defined( __GNUC__ )  &&  defined( __LP64__ )  &&  __LP64__ >= 1  && \
(_GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)) && \
(defined( __x86_64__ ) || defined( __i386__ ) ||\
defined( __i486__ ) || defined( __i586__ ) || defined( __i686__ ))

#include <string.h>

__asm__(".symver memcpy, memcpy@GLIBC_2.2.5");

extern "C"
{
void *__wrap_memcpy(void *dest, const void *src, size_t n)
{
return memcpy(dest, src, n);
}
}

#endif


Related Topics



Leave a reply



Submit