How do I let Callgrind access my Qt project's source code? - qt

I built a Qt project in Debug mode with Qt Creator, ran Callgrind to generate profiling data and tried loading it into Cachegrind. I noticed that I only see profiling information for Qt classes, so I figured I must have forgotten to turn on a crucial flag.
Qt Creator's qmake command looks like this:
qmake /path/to/project/MyProject/MyProject.pro -r -spec linux-g++-64 CONFIG+=debug
Sample compile output for one file:
g++ -c -m64 -pipe -g -Wall -W -D_REENTRANT -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++-64 -I../Flowchart -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include -I. -I. -I../Flowchart -I. -o main.o ../Flowchart/main.cpp
The -g flag is there, so debug information should be available. I verified this by running gdb on the executable and trying to look at some random source code with l.
The Callgrind command I used was:
valgrind --tool=callgrind ./MyProject
What am I missing here?

You should do:
valgrind --tool=callgrind --trace-children=yes --demangle=yes ./MyProject
Also depending on the distribution of Linux you may have to make sure that you have the Debug information in the QT libraries you are linking against.

Related

QtCreator: Header files not found when using CMake

I have tried this on multiple platforms, experiencing the same issue every time.
I successfully build and run my C++ OpenFrameworks application using QtCreator - no problems are encountered.
Then, I successfully use qmake to generate the project file.
Yet when I attempt to make the executable, I receive the following error:
make
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -c -pipe -stdlib=libc++ -O2 -std=gnu++1z -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk -mmacosx-version-min=12 -Wall -Wextra -fPIC -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I. -I. -I/opt/homebrew/lib/QtGui.framework/Headers -I/opt/homebrew/lib/QtCore.framework/Headers -I. -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/System/Library/Frameworks/OpenGL.framework/Headers -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/System/Library/Frameworks/AGL.framework/Headers -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/System/Library/Frameworks/OpenGL.framework/Headers -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/System/Library/Frameworks/AGL.framework/Headers -I/opt/homebrew/share/qt/mkspecs/macx-clang -F/opt/homebrew/lib -o main.o src/main.cpp
src/main.cpp:1:10: fatal error: 'ofMain.h' file not found
#include "ofMain.h"
^~~~~~~~~~
1 error generated.
make: *** [main.o] Error 1
I can go into the .pro file and add things to the include path manually, but I don't see why these includes aren't generated automatically?
I think I recognized your problem.
The file name is main.cpp in the src/ folder. Based on its location in the src/ folder, I think your ofMain.h file is also in the src/ folder. Now a question: did you add src/ to your include path? If not with the following line:
INCLUDEPATH += \
src/
It should work now I hope.
Have a nice day!

How can I build Qt projects using Bazel?

I have a directory with Qt 5.15 for gcc_64 on Ubuntu. I know I need to link the proper .so (or .la?) file in the lib subdirectory and include the headers from the include directories. I would need to do this for several Qt modules. This is my second day using Linux and Bazel, and I'm not sure how to get a basic build setup going. I have tried using cc_import and cc_library so far without sucess.
I know everything is done automatically for you when using Qt Creator, but I am using Visual Sudio Code with a the Bazel build system for integration of other projects.
Here is a piece of the compiler input for a sample project when using Qt Creator.
g++ -c -pipe -g -Wall -Wextra -D_REENTRANT -fPIC -DQT_QML_DEBUG
-DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../addressbook -I. -I/home/joseph/Qt/5.15.0/gcc_64/include -I/home/joseph/Qt/5.15.0/gcc_64/include/QtWidgets -I/home/joseph/Qt/5.15.0/gcc_64/include/QtGui -I/home/joseph/Qt/5.15.0/gcc_64/include/QtCore -I. -isystem /usr/include/libdrm -I/home/joseph/Qt/5.15.0/gcc_64/mkspecs/linux-g++
-o addresswidget.o ../addressbook/addresswidget.cpp
I see macros, includes, and libraries added. What is all the other stuff?
An alternate route I have decided is to build a library out of a qt project and use that with Bazel. With this, how would I access GUI objects? Would I have signal and slots?

r compile packages fails with Mac catalina

Since I installed Catalina, any attempt to compile an R package fails. My system is set up to use home-brew. The failure messages look like this:
/usr/local/clang8/bin/clang -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I../inst/include -I/usr/local/clang8/include -I/usr/local/Cellar/gcc/8.3.0_2/include -fopenmp -fPIC -Wall -g -O2 -c R_register_native.c -o R_register_native.o
In file included from R_register_native.c:1:
/Library/Frameworks/R.framework/Resources/include/R.h:55:11: fatal error: 'stdlib.h' file not found
# include <stdlib.h> /* Not used by R itself, but widely assumed in packages */
After googling I found this link in the home-brew site on GitHub. I can't follow much of the discussion but it seems that Apple removed the usr/include directory and that the home-brew folks are looking for a solution. I don't immediately have a need to compile these packages so my plan is to wait until home-brew finds a solution. But if there is an easy one now, please share.
After some additional searching I found this link with a bunch of discussion about this problem, a lot of which I didn't understand. But this bit of code seemed promising.
sudo ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/* /usr/local/include/
I ran it, rebooted my mac, opened RStudio and got the list of new package updates. Ran the update, answering yes to compile. Lots of messages and some warnings but at the end of it all, there were no errors. But all the messages start with something like
/usr/local/clang8/bin/clang -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I../inst/include -I/usr/local/clang8/include -I/usr/local/Cellar/gcc/8.3.0_2/include -fopenmp -fPIC -Wall -g -O2 -c R_register_native.c -o R_register_native.o
When I cd into /usr/local/clang8/bin and get the version of clang it is Apple clang version 11.0.0. Also clang symlinks to clang-8 and clang++ symlinks to clang
The contents of /usr/local/Cellar/gcc is a directory called 9.2.0_1. When I go to /usr/bin and run gcc --version I get messages about this being Apple clang version 11.0.0. It seems like R is compiling using the Apple clang version. Is that a problem? Is there some way to move everything to using the brew version of clang? FYI, here's my current path - /usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Library/Apple/bin:/Library/TeX/texbin:/opt/X11/bin:/usr/local/CrossPack-AVR/bin:/usr/local/git/bin

Adding -lrt to the compilation when running ./configure

I've been messing around with some source files (coreutils package source for example), adding to them asynchronous I/O functionality. Now I want to compile, but I need to add -lrt flag to gcc.
What I did is shoving it somewhere to the Makefile file. It once took me an hour to find where to put it so it will work.
I wonder, is there a way to add it during the ./configure phase, so the Makefile will be created automatically and things will just compile with the -lrt flag?
I've tried configuring the additional flag with:
./configure CFLAGS='-g -O2 -lrt'
and indeed I see a change in the Makefile, but it still doesn't work.
Using
make V=1
I see that make executes:
gcc -std=gnu99 -g -O2 -lrt -Wl,--as-needed -o src/wc src/wc.o src/libver.a lib/libcoreutils.a lib/libcoreutils.a
notice that -lrt is somewhere in the middle, so for some reason it doesn't work. But if this get executed:
gcc -std=gnu99 -g -O2 -Wl,--as-needed -o src/wc src/wc.o src/libver.a lib/libcoreutils.a lib/libcoreutils.a -lrt
it works. Notice that -lrt is at the end.
How can I append a flag to the end automatically through ./configure? or is there some other way to do that?
Partial Solution:
After running ./configure, I've edited the Makefile and added -lrt to the LDADD variable - that done the trick.

QT5-alpha build errors in Ubuntu-Linux 11.10

I tried the instructions of building latest QT5-Alpha(http://qt-project.org/wiki/Qt-5-Alpha
http://qt-project.org/wiki/Building_Qt_5_from_Git)
from GIT,but facing compilation in wayland files
Ubuntu Linux 11.10
__make[4]: Entering directory `/home/xyz/build/newqt5/qt5/qtwayland/src/plugins/platforms/wayland'
g++ -c -pipe -g -fvisibility=hidden -fvisibility-inlines-hidden -D_REENTRANT -Wall -W -fPIC -DQT_NO_LIBUDEV -DQ_PLATFORM_WAYLAND -DQT_NO_WAYLAND_XKB -DQT_WAYLAND_GL_SUPPORT -DQT_WAYLAND_WINDOWMANAGER_SUPPORT -DQ_FONTCONFIGDATABASE -DQT_COMPILES_IN_HARFBUZZ -DQT_PLUGIN -DQT_GUI_LIB -DQT_CORE_LIB -I/home/xyz/build/newqt5/qt5/qtbase/mkspecs/linux-g++ -I. -I/home/xyz/build/newqt5/qt5/qtbase/include/QtCore/5.0.0 -I/home/xyz/build/newqt5/qt5/qtbase/include/QtCore/5.0.0/QtCore -I/home/xyz/build/newqt5/qt5/qtbase/include/QtCore -I/home/xyz/build/newqt5/qt5/qtbase/include/QtGui/5.0.0 -I/home/xyz/build/newqt5/qt5/qtbase/include/QtGui/5.0.0/QtGui -I/home/xyz/build/newqt5/qt5/qtbase/include/QtGui -I/home/xyz/build/newqt5/qt5/qtbase/include/QtPlatformSupport/5.0.0 -I/home/xyz/build/newqt5/qt5/qtbase/include/QtPlatformSupport/5.0.0/QtPlatformSupport -I/home/xyz/build/newqt5/qt5/qtbase/include/QtPlatformSupport -I/home/xyz/build/newqt5/qt5/qtbase/include -I../../../shared -Igl_integration/xcomposite_share -I.moc/debug-shared -o .obj/debug-shared/qwaylandintegration.o qwaylandintegration.cpp
In file included from qwaylandshmwindow.h:45:0,
from qwaylandintegration.cpp:46:
qwaylandwindow.h:112:18: error: ‘wl_callback_listener’ does not name a type
make[4]: *** [.obj/debug-shared/qwaylandintegration.o] Error 1_
Any pointers to overcome this?
Download the alpha source package here: http://releases.qt-project.org/qt5.0/alpha/ and use the steps in README file.
The master in git is NOT what was released as alpha. The build scripts are different. You have to wait for them to add alpha tag to pull it from git. But why not just grab the gz file?

Resources