Undefined reference to ` SEM appears when compiling with tcmalloc_ init’

Tcmalloc is an open source memory management library of Google. As a substitute of glibc malloc, the efficiency of tcmalloc is several times that of gclibc malloc. It’s very easy to use tcmalloc in the project. We use the static compilation method. By adding the link option – ltcmalloc, we can statically link libtcmalloc. A. However, an unexpected situation occurred during the link process, and the following error was reported:

../3party/static_libs/libtcmalloc.a(libtcmalloc_la-linuxthreads.o): In function `TCMalloc_ListAllProcessThreads':
linuxthreads.cc:(.text+0x333): undefined reference to `sem_init' linuxthreads.cc:(.text+0x41c): undefined reference to `sem_post'
linuxthreads.cc:(.text+0x477): undefined reference to `sem_destroy'
../3party/static_libs/libtcmalloc.a(libtcmalloc_la-linuxthreads.o): In function `ListerThread':
linuxthreads.cc:(.text+0x67b): undefined reference to `sem_wait' collect2: error: ld returned 1 exit status

sem_ Init is the library function, and the header file is # include & lt; semaphore.h>。 After searching a lot of materials, it is said that the link option lpthread is missing, but our makefile has the lpthread option, and we tried to add ptthread in the compilation option, but it still has no effect. After trying all kinds of methods, we finally tried to put the lpthread option behind the tcalloc option, and we passed it. It’s quite a Wulong

Similar Posts: