Compile and debug C++11 project in Qt Creator



  • Hello Everyone,

    I am a chemical engineering master's student working on developing a molecular simulation in C++11. I am very new to Qt Creator, and I have a question that is probably extremely basic for most users. I spent a while looking around for answers on StackOverflow and on Google in general, but most of the related cases are more advanced than what I need. It's such a simple thing, yet I'm at my wit's end. It is a bit embarassing to ask, but here it goes anyway.

    I am using Ubuntu 14.04.1 and Qt Creator 3.3.0; gcc version (and g++) is 4.8.2. I am using C++11 standard for my code. I installed Qt Creator because I've heard great things about its development and debugging capabilities, and because the native Ubuntu gdb debugger has no graphical interface.

    My C++ source code is located in ~/research/lcmc-qt-creator/src/, and within the src/ directory there is a MAKE/ directory that has different makefiles for compilation on different systems (Mac OS X, Linux, and so on). Within the MAKE/ directory, one of many files I have is called "Makefile.serial_debug".

    When I compile my code for debugging in gdb on Ubuntu, I go to ~/research/lcmc-qt-creator/src/ and type "make serial_debug" in the terminal. This generates executable file called "spk_serial_debug" in ~/research/lcmc-qt-creator/src/.

    To debug the code, I type "gdb ./spk_serial_debug" in the terminal (while in the ~/research/lcmc-qt-creator/src/ directory). This, of course, opens up gdb, which is waiting for commands. After setting some breakpoints, I type (in gdb) "run < in.parameters" to run the code until the specified breakpoint is reached.

    My executable "spk_serial_debug" requires two files, "array.txt" and "in.parameters", to be present in the same directory as "spk_serial_debug". But unlike the case with "in.parameters", I don't have to mention "array.txt" in any commands I use to run the code.

    So my question is: how can I compile the code and debug it in Qt Creator? Pressing the "Build" button, and pressing "F5" to debug, causes the same message in "Compile Output" tab in Qt Creator:

    21:58:10: Running steps for project lcmc-qt-creator...
    21:58:10: Starting: "/usr/bin/make" all
    make: *** [all] Error 1
    21:58:10: The process "/usr/bin/make" exited with code 2.
    Error while building/deploying project lcmc-qt-creator (kit: Desktop)
    When executing step "Make"
    21:58:10: Elapsed time: 00:00.

    I obviously did not specify that I want Makefile.serial_debug file from ~/research/lcmc-qt-creator/src/MAKE/ directory to be used for compilation, but I don't know how to do so. And I don't know how I would provide the "in.parameters" file to gdb when I'm able to run the Debug mode in Qt Creator.

    Thank you very much for your time and any help. I wish I could ask a more sophisticated question, but I'm stuck on this basic thing. :(



  • Welcome to DevNet,

    How did you create a qtcreator project?

    Since you are using existing project I assume that you did "Import Existing Project":http://doc.qt.io/qtcreator/creator-project-generic.html

    After qtcreator imported all files you will need to go to "Projects" settings and "configure your project":http://doc.qt.io/qtcreator/creator-configuring-projects.html
    There you need to

    change "build settings":http://doc.qt.io/qtcreator/creator-build-settings.html, "set custom build step":http://doc.qt.io/qtcreator/creator-build-settings.html#adding-custom-build-steps

    change "run settings":http://doc.qt.io/qtcreator/creator-run-settings.html

    And then try to build and run your project from QtCreator.



  • Thank you very much for your guidance and the unexpectedly prompt reply!

    I got it to run in regular and debug mode. All I really had to do was to import the project's src/ directory with all the source code (I did it in the exact way you assumed I did), and then follow the documentation you provided.

    For the benefit of those who might be reading this later and are stuck in the same place I was, I'll summarize the resolution to my predicament:

    To compile the code: in "Projects" mode, under "Build Settings"/"Build Steps", I added "serial_debug" in the "Make arguments" field and unchecked "all" under "Targets". Under "Build Settings"/"Clean Steps", I added "clean-all" argument and left all of the "Targets" unchecked.

    To run the code: in "Projects" mode, under "Run Settings"/"Run", in the "Executable" field I found the executable file using the menu from the "Browse" button, and wrote "< in.relax_aniso_npt" in the "Arguments" field.

    To debug the code: in "Tools" drop down I selected "Options"/"Debugger"/"GDB" and wrote "< in.relax_aniso_npt" in the "Additional Startup Commands" field.

    All commands were written without quotes.

    Now I'm able to run and debug the code in Qt Creator! The only strange thing is that the output "text" files my simulation produces are "binary" when they are produced during the debug mode instead of being the normal "text" files when created in the run mode. But I don't think I need them for debugging.

    Again, thank you very much! / Огромное спасибо Вам! :)



  • Glad that it works now.
    Рад что удалось помочь :-)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.