1

Recently I wanted to profile my cpp code and came across gperftool, but there aren't really clear instructions on how to use it with Mac. So far I have run brew install gperftools and wanted to compile my simple cpp file which just outputs "Hello world!". I run g++ main.cpp -lprofiler -o main but get error ld: library not found for -lprofiler. I really appreciate it if you could guide me or should me a tutorial where it's easy to follow. Thanks :)

Edit: Currently I am using MacOS with new M1 chip (not sure if that can cause any issue)

Orif Milod
  • 465
  • 1
  • 7
  • 17
  • Here is a page to learn about gperftools: https://developer.ridgerun.com/wiki/index.php?title=Profiling_with_GPerfTools – Orif Milod Apr 10 '21 at 16:25

2 Answers2

1

So brew didn't install the binaries and that's it.

Follow these steps if you are having a hard time making it work

  1. clone https://github.com/gperftools/gperftools
  2. run ./autogen.sh
  3. run ./configure
  4. make && sudo make install
  5. you should see some path where the binaries where installed, if you wanna take a look at it to make sure (mine was /usr/local/lib)
  6. Profit
Orif Milod
  • 465
  • 1
  • 7
  • 17
0

I found you can also use the -L$(brew --prefix gperftools)/lib flag to tell g++ where to look for the libraries if you don't want to install with make.

Alex McDermott
  • 151
  • 1
  • 1
  • 8