msw1520
msw1520

Reputation: 128

Heap profiling with gperftools and Rcpp: Failing to link against tcmalloc

I'm trying to get a memory profile of my C++ library running under R. Following https://gperftools.github.io/gperftools/heapprofile.html I link against tmalloc, but the build fails.

g++ -std=gnu++11 -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro RcppExports.o -L../inst/libs -l:my_package_shared.so -Wl,-rpath,$ORIGIN -ltcmalloc ...

installing to /tmp/bazel/R/lib/my_package
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
src/tcmalloc.cc:332] Attempt to free invalid pointer 0x55a1f8d72e70 
Aborted (core dumped)
ERROR: loading failed
* removing '/tmp/bazel/R/lib/my_package/'

Build system is bazel, build command is

bazel build -c opt --copt="-ggdb" --copt="-fno-omit-frame-pointer" --linkopt="-ltcmalloc" //my_package

Is this doable? Would welcome experiences with heap profiling C++ code called from R. FTR, CPU profiling of Rcpp with gperftools works well. It's memory profiling that's troubling me. Thanks.

Upvotes: 0

Views: 209

Answers (0)

Related Questions