【发布时间】:2016-02-24 05:13:14
【问题描述】:
我已经克隆了 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 时,它给了我一个错误。
可能是什么问题?也许有什么想法?
【问题讨论】:
-
您能否向我们提供您收到的错误消息?所以我们可以帮助你。
标签: c++ malloc tcmalloc gperftools