Ubuntu的11.10联perftools库 [英] Ubuntu 11.10 linking perftools library

查看:137
本文介绍了Ubuntu的11.10联perftools库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不能让GCC在Ubuntu 11.10中的谷歌perftools -lprofiler正确链接。
这个问题似乎是该链接器放弃不直接在程序中使用的库。

一个例子会有所帮助。

让我们把这种main.cpp中:

 的#include<&math.h中GT;诠释的main()
{
  双重价值;
  的for(int i = 0; I< 1000000;我++)
  {
    对于(INT J = 0; J< 1000; J ++)
      值=开方(100.9);
  }  返回0;
}

使用编译:

  G ++ -c的main.cpp -o main.o中
G ++ main.o中-o主要-lm -lprofiler

使用LDD ./main检查可执行文件:

  Linux的vdso.so.1 => (0x00007fff5a9ff000)
  libc.so.6的= GT; /lib/x86_64-linux-gnu/libc.so.6(0x00007f32bc1c9000)
  /lib64/ld-linux-x86-64.so.2(0x00007f32bc593000)

通常情况下,我会运行:

  CPUPROFILE =的/ tmp / profile文件./main

要产生的资料输出。但由于轮廓库中没有任何资料输出链接生成的。

我已经取得了一定的探查库是在我的搜索路径,并尝试直接对链接共享库和静态库。

以上测试工作正常,在Ubuntu 10.04,Ubuntu的10.10,Ubuntu的11.04,SUSE 12.1,和Fedora 16。

此外,一旦我包括使用分析器(如ProfilerStart()和ProfilerStop()),然后探查库被链接到可执行文件。函数调用

如何让GCC任何想法在探查库链接?

感谢。


解决方案

  G ++ main.o中-o主要-lm -lprofiler


由于another.anon.coward评论,你很可能下跌的牺牲品你的 G ++ 使用 - 按需链接器标志。试试这个:

G ++ main.o中轮候册,

   - 无按需-lprofiler轮候册, - 按需

注:


  1. G ++ 已经添加了 -lm ,无需添加一遍

  2. 按需回 -
  3. 这把是很重要的。如果不这样做很可能会导致您链接到你真的不需要额外的库。

I can't get gcc in Ubuntu 11.10 to properly link in the google perftools -lprofiler. The problem seems to be that the linker discards libraries which are not directly used in a program.

An example will help.

Let's call this main.cpp:

#include <math.h>

int main()
{
  double value;
  for (int i=0; i < 1000000; i++)
  {
    for (int j=0; j < 1000; j++)
      value = sqrt(100.9);
  }

  return 0;
}

Compile using:

g++ -c main.cpp -o main.o
g++ main.o -o main -lm -lprofiler

Check the executable using ldd ./main:

  linux-vdso.so.1 =>  (0x00007fff5a9ff000)
  libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f32bc1c9000)
  /lib64/ld-linux-x86-64.so.2 (0x00007f32bc593000)

Normally, I would run:

CPUPROFILE=/tmp/profile ./main

to produce profile output. But since the profile library is not linked in no profile output is generated.

I've made sure the profiler library is in my search path, and have tried directly linking against the shared library and static library.

The above test works fine on Ubuntu 10.04, Ubuntu 10.10, Ubuntu 11.04, SUSE 12.1, and Fedora 16.

Also, once I include function calls that use the profiler (such as ProfilerStart() and ProfilerStop()), then the profiler library gets linked into the executable.

Any ideas on how to get gcc to link in the profiler library?

Thanks.

解决方案

g++ main.o -o main -lm -lprofiler

As another.anon.coward commented, you are likely falling victim of your g++ using --as-needed linker flag. Try this instead:

g++ main.o -Wl,--no-as-needed -lprofiler -Wl,--as-needed

Notes:

  1. g++ already adds -lm, no need to add it again
  2. It is important to turn --as-needed back on. Not doing so will likely cause you to link to additional libraries that you don't really need.

这篇关于Ubuntu的11.10联perftools库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆