我已经克隆了 google-perf git 树。
> ./autogen.sh
> ./configure --enable-frame-pointers --prefix=/usr/
> make
> sudo make install
上述所有步骤均成功。我可以在 /usr/include/gperftools/tcmalloc.h 等中看到头文件
我的程序
#include <stdio.h>
#include <gpertools/malloc_extension.h>
#include <iostream>
int main()
{
const unsigned int tcmalloc_stats_buf_len_ = 32768;
char tcmalloc_stats_buf[tcmalloc_stats_buf_len_];
MallocExtension::instance()->GetStats(tcmalloc_stats_buf,
tcmalloc_stats_buf_len_);
printf("%s ",tcmalloc_stats_buf);
fflush(stdout);
}
汇编
g++ -ltcmalloc my_prog.c -o my_prog
my_prog.cc: undefine reference to MallocExtension::instance
如果我注释掉 GetStats 行,那么编译工作正常。所以我假设它与 tcmalloc 链接。但是,当我尝试访问 API 时,它给了我一个错误。
可能是什么问题呢?也许有什么想法?