Linking with libtcmalloc ubuntu
Asked Answered
P

2

8

I had installed the package libtcmalloc-minimal0

but when I try to compile my program with flag

-ltcmalloc-minimal0

I am getting error

/usr/bin/ld: cannot find -ltcmalloc_minimal0

I had checked /usr/lib and the library is there

More Info

dpkg gives following o/p

dpkg -L libtcmalloc-minimal0
/.
/usr
/usr/lib
/usr/lib/libtcmalloc_minimal.so.0.0.0
/usr/lib/libtcmalloc_minimal_debug.so.0.0.0
/usr/share
/usr/share/doc
/usr/share/doc/libtcmalloc-minimal0
/usr/share/doc/libtcmalloc-minimal0/TODO
/usr/share/doc/libtcmalloc-minimal0/AUTHORS
/usr/share/doc/libtcmalloc-minimal0/copyright
/usr/share/doc/libtcmalloc-minimal0/changelog.gz
/usr/share/doc/libtcmalloc-minimal0/README.gz
/usr/share/doc/libtcmalloc-minimal0/changelog.Debian.gz
/usr/lib/libtcmalloc_minimal.so.0
/usr/lib/libtcmalloc_minimal_debug.so.0

and I am compiling for 64 bit mode

and library is also 64 bit

file  /usr/lib/libtcmalloc_minimal.so.0.0.0
/usr/lib/libtcmalloc_minimal.so.0.0.0: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, stripped
Paid answered 8/11, 2011 at 9:17 Comment(3)
Is it called exactly /usr/lib/libtcmalloc_minimal0.so? Is the library for the right architecture? (you could be compiling in 64-bits mode, whereas the library you installed is 32-bits)Definiens
both library and program is 64 bit modePaid
So what part of the code would require libtcmalloc-minimal? Does new/delete statement require it?Relay
D
7

You can't link simply to a file with -l if it doesn't end exactly with .so, since the linker assumes a particular naming convention (lib*.so).

You have several choices:

  • Install libtcmalloc-minimal0-dev if it exists, which should provide the .so dynamic link.

  • Create the symlink yourself: cd /usr/lib; ln -s libtcmalloc_minimal.so.0.0.0 libtcmalloc_minimal.so; cd -

  • Link directly to the library without the symlink by using gcc test.c /usr/lib/libtcmalloc_minimal.so.0.0.0

  • Link using the -l option using the full name: -l:libtcmalloc_minimal.so.0.0.0

Definiens answered 8/11, 2011 at 9:53 Comment(1)
So what part of the code would require libtcmalloc-minimal? Does new/delete statements require it?Relay
T
0

Running dpkg -L libtcmalloc-minimal0 will show you that the library is /usr/lib/libtcmalloc_minimal.so.0 so the correct option should be -ltcmalloc_minimal without any digit

Tyus answered 8/11, 2011 at 9:20 Comment(2)
same error with ltcmalloc_minimal see the edit to see dpkg o/pPaid
perhaps you need to run ldconfig. To understand what gcc is doing, pass it the -v flag.Tyus

© 2022 - 2024 — McMap. All rights reserved.