gperftools not installing -lprofiler on Mac after installing it with brew - c++

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)

So brew didn't install the binaries and that's it.
Follow these steps if you are having a hard time making it work
clone https://github.com/gperftools/gperftools
run ./autogen.sh
run ./configure
make && sudo make install
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)
Profit

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.

Related

How to recover system gcc compiler on centos 6

I am running centos 6 on a cluster. I installed the latest gcc-8.2.0. and made a link "ln -sf /usr/bin/gcc-8.2 gcc".
I did the same for g++ and gfortran.
I wanted to reinstall gcc-8.2.0 and went ahead to
make clean
in the gcc-8.2 directory.
When I try
./configure
I get that C compiler cannot create executables
The links I made are broken.
The system gcc-4.4.7 cannot be found
which gcc
gives no gcc
sudo yum install gcc gcc-c++
gives gcc is already installed.
I tried to install an rpm, which fails because of dependencies.
I have pg compilers installed in /opt/pgi
When I configure with
CC=/path to/pgi/bin/pgcc FC=/path to/pgi/bin/pgfortran ./configure
I still get C compiler cannot create executables
I tried the following c++ programm
#include <iostream>
using namespace std;
int main() {
cout << "Hello world!" << endl;
return 0;
}
With the command
/opt/pgi/linux_86_64/12.08/bin/pgcpp hello.cpp -o hello
It gives compilation error that float.h not found. On another linux PC with working gcc, the program works with the command
g++ hello.cpp -o hello
I will appreciate any assistance to either find the systemgcc or use pg compilers to compile gcc if possible
I admit it is a big mess which will require OS reinstallation and reconfiguration. But then I did
sudo yum install compat-gcc-34
Now I have gcc34 and configure of gcc-8.2 goes through without "c compiler cannot create executables". (Note that the ./configure referred to in earlier post was actually
../gcc_8_2_release/configure
inside "gcc_8_2_release_build, so gcc was not being built in its source directory.
The problem I have now is with make, which needs g++, giving error
uint_t(64) or int_t(64) not found.
Thanks all who have gone through this post, for your patience.
Any assistance will be appreciated.
Here is how I got out of this mess.
With the following two commands
sudo yum install compat-gcc-34-c++
sudo yum install compat-gcc-34-g77
I was able to install the older version of gcc, c++ and g77. Then I was able to build gcc-8.2.
Now I have a functional system with the latest gcc, yes it may need re-installation/re-configuring but it is fully functional.
I have learnt a lot and very much appreciate the comments and guidelines of #Basile. However, at one point he was rather negative and discouraging.
But thanks to my belief and perseverance, and more importantly browsing the knowledge shared by others, I have been able to recover what I was beginning to be convinced was a lost cause.
Thanks all.
This is more a sysadmin question than a programming one.
My recommendations:
don't mess your /usr/bin/. Leave your package manager yum to fill it -and never add anything inside it without yum ; so remove manually any symlinks you made there (by mistake)
reinstall the old system gcc 4.4 and g++ 4.4 (using yum)
rebuild your GCC 8 from scratch from its source code. Configure it with --program-suffix=-8 (but no --prefix, or a --prefix=$HOME/soft/ if you don't have root access). So it will install /usr/local/bin/gcc-8 and /usr/local/bin/g++-8 etc... (or, if you have given --prefix=$HOME/soft/ , a $HOME/soft/bin/gcc-8 etc...)
create a $HOME/bin/ if you don't have already one
be sure to have $HOME/bin/ early in your $PATH (before /usr/bin/)
add a symlink ln -sv /usr/local/bin/gcc-8 $HOME/bin/gcc and likewise for g++ etc..
Then, when you type gcc you are getting that symlink to /usr/local/bin/gcc-8 etc.
If you cannot write to /usr/local/ (e.g. because you don't have root permission...) you could pass --prefix=$HOME/soft/ to GCC 8 .../configure then replace /usr/local/ above with $HOME/soft/
If you are the sysadmin and can write to /usr/local/ and have to set up things for many users: add a symlink ln -s /usr/local/bin/gcc-8 /usr/local/bin/gcc etc and ask your users to put /usr/local/bin/ in their $PATH before /usr/bin/
BTW, notice that it is explicitly documented that GCC 8 (or others) need to be built outside of its source tree: in Installing GCC you can read:
First, we highly recommend that GCC be built into a separate directory from the sources which does not reside within the source tree.
(the "highly recommend" should be considered as a polite way to say "you absolutely should")
So your ./configure was another mistake.
It could happen that you messed up your system more seriously than you thought (and perhaps you need to reinstall, or to call Redhat support).
PS. I don't know Redhat (used it only in the previous century). My favorite distro is Debian/testing or Debian/unstable (and my computers are desktops, not clusters).
This problem was solved by the following commands
sudo yum install compat-gcc-34-c++
sudo yum install compat-gcc-34-g77
Once this older version of gcc is installed, the latest version, gcc-8.2 was built and the system is no longer messed terribly. It is very healthy and fit.

Can't compile with gtk+ on codeblock ubuntu

So i'm really new at C and C++ (like.....i started a week ago).
I have this c++ script that i'm working on, I made an interface in gtk+ that work fairly well. Till now i used window 10 but I had to do some multithreading (using pthread) and window is quite bad at handling those. So i decided to work on Ubuntu 16.
There begin the trouble, can't figure out how to make everything works....I'll try to be specific.
I'm using Ubuntu 16.0.4, mingw, openal and gtk+, to install everything i used :
sudo apt-get install gpp gcc g++ mingw-w64 codeblocks
sudo apt-get install libsdl-image1.2 libsdl-image1.2-dev
sudo apt-get install libopenal-dev libalut-dev
sudo apt-get install libgtk2.0-dev build essential
and if i understand it right it install the latest package of everything.
If i create an gtk+ project and test it with a simple code it works just fine....But when i try to test MY code i get an "fatal error: config.h file not found" in resample_defs.h...
And if I paste my GTK+ script that work earlier in place of my code i get the same error. So apparently gtk+ work with *.c but not with *.cpp
how do i fix that ?
Any help would be welcome at this point...
Ok, got it. I feel stupid now.
Resample_defs.h WAS slignthly changed by de guy that created the script I work on.
There was an
#if !defined(WIN32) //which force the include of config.h
But since i'm now in Linux OS it doesn't work, so add an :
#ifdef __linux__
well, that's that. Thank you very much for your help ! I can code now !

How to build freetype on Cent OS 6.5?

I am trying to build the freetype library I got from here: http://download.savannah.gnu.org/releases/freetype/freetype-2.5.3.tar.gz But I am really failing to do so.
I am using Cent OS 6.5, and the compiler is g++ 4.8.2. I need the library to be release, static and 64 bit. Is there anyone who can explain this in simple steps, please?
I am trying to compile my program and I am getting an error telling me I need some freetype .so file.
Before building it myself, I would try
yum install freetype2-devel
If that doesn't install the library you need, you can try configure with something like (enable-static for static build and the target triplet)
./configure --enable-static x86_64-pc-linux-gnu
Then you can build it by running
make
Finally, you can install it by running
sudo make install

error while loading shared libraries

I'm trying to install Code::Blocks from source. There is an `anarchy' folder on my university's CS department's mainframe, where anyone can install anything, basically.
wxwidgets is a dependency of Code::Blocks, and I'm trying to put wxGTK, as it's called, into my own folder on `anarchy', which works fine.
I then compile Code::Blocks with the correct configure flags so that it recognizes wxwidgets 2.8 during the installation. But then, when I want to run `codeblocks', it says
codeblocks: error while loading shared libraries: libwx_gtk2u-2.8.so.0
Obviously I don't have su access as I am only a student at the university. Is there a way to resolve this without su privileges? They are Debian 5.0 systems, I believe, with all dependencies but wxwidgets, so I had to build that on my own.
This is how I solved this:
First I ran the configure script like this:
$ ./configure --prefix=/pub/anarchy/<myname>/codeblocks --with-wx-config=/pub/anarchy/<myname>/wxGTK/bin/wx-config
then:
$ export LDFLAGS="-Wl,-R /pub/anarchy/<myname>/wxGTK/lib"
$ make
$ make install
Now codeblocks finds libwx_gtk2u-2.8.so.0.
An alternative solution (untested) according to comments would be:
$ ./configure LDFLAGS="-Wl,-R /path/to/wxGTK/lib" # other configure flags omitted
$ make
$ make install

Enabling OpenGL in wxWidgets

I installed the wxWidgets source code, compiled it and am linking the libraries thus obtained with my application code. Now I need to use OpenGL in my wxWidgets application. How do I enable this?
For building on Windows with project files:
Assume $(WXWIDGETSROOT) is the root directory of your wxWidgets installation.
Open the file $(WXWIDGETSROOT)\include\wx\msw\setup.h
Search for the #define for wxUSE_GLCANVAS.
Change its value from 0 to 1.
Recompile the library.
For building on Linux and other ./configure based platforms:
Just use ./configure --with-opengl
(A mashup answer from two partial answers given by others)
If you're using configure to build wxWidgets you just need to add --with-opengl to your command line.
Just to add a little bit... If you're on linux you need to watch the logs when running configure. If it can't find opengl dev packages then it will turn opengl off with one line of warning which is easy to miss.
run it like this to make it more obvious what development libraries you're actually missing (it looks like the --with-opengl is on by default in 3.0.0 and possibly earlier versions of wxwidgets, but it can't hurt to include it I suspect).
./configure --with-opengl > configure.log
Once configure can find all the dev libs you think you're going to use you need to rebuild wxwidgets:
make
sudo make install
I had to install these on linux mint to make wxwidget's configure happy as far as opengl was concerned (and should also work for ubuntu) to get the dev libs I needed.
sudo apt-get install mesa-common-dev
sudo apt-get install freeglut3-dev
(Assume $(WX_WIDGETS_ROOT) is the root directory of your wxWidgets installation.)
Open the file $(WX_WIDGETS_ROOT)\include\wx\msw\setup.h
Search and find the option wxUSE_GLCANVAS. Change its value from 0 to 1.
Recompile the library.