c++ gperftools在使用brew安装后未在Mac上安装-lprofiler

lrl1mhuk  于 4个月前  发布在  Mac
关注(0)|答案(3)|浏览(65)

最近我想分析我的cpp代码,遇到了gperftool,但没有关于如何在Mac上使用它的明确说明。到目前为止,我已经运行了brew install gperftools,并希望编译我的简单cpp文件,它只是输出“Hello world!“.我运行g++ main.cpp -lprofiler -o main,但得到错误ld: library not found for -lprofiler.我真的很感激,如果你能指导我,或者应该我的教程,它很容易遵循.谢谢:)
编辑:目前我使用的是带有新M1芯片的MacOS(不确定这是否会导致任何问题)

w8ntj3qf

w8ntj3qf1#

所以brew没有安装二进制文件,就是这样。
如果你很难让它工作,请遵循以下步骤
1.克隆https://github.com/gperftools/gperftools

  1. run ./autogen.sh
    1.运行./configure
  2. make && sudo make install
    1.你应该看到一些二进制文件安装的路径,如果你想看看它以确保(我的是/usr/local/lib
    1.利润
sshcrbum

sshcrbum2#

我发现你也可以使用-L$(brew --prefix gperftools)/lib标志来告诉g++如果你不想用make安装的话去哪里找库。

irlmq6kh

irlmq6kh3#

还有另一种选择。您可以通过调用
brew info gperftools

==> gperftools: stable 2.13 (bottled), HEAD
Multi-threaded malloc() and performance analysis tools
https://github.com/gperftools/gperftools
/opt/homebrew/Cellar/gperftools/2.13 (101 files, 4.5MB) *
...

字符串
然后你只需要为编译器指定库和头文件的位置。这可以用CMake这样做:

target_include_directories(Target PRIVATE /opt/homebrew/Cellar/gperftools/2.13/include)
target_link_directories(Target PRIVATE /opt/homebrew/Cellar/gperftools/2.13/lib)
target_link_libraries(Target PRIVATE profiler)

相关问题