MRC/Tutorials/Setting up an IDE: Difference between revisions

From Control Systems Technology Group
Jump to navigation Jump to search
No edit summary
Line 11: Line 11:
# Make the file executable: <pre>chmod +x <INSTALL_FILE></pre>
# Make the file executable: <pre>chmod +x <INSTALL_FILE></pre>
# Run the installation: <pre>./<INSTALL_FILE></pre>
# Run the installation: <pre>./<INSTALL_FILE></pre>
If you installed Qt Creator in the default path, you can run it by calling:
<pre>
~/qtcreator-3.3.2/bin/qtcreator
</pre>


= Use with ROS =
= Use with ROS =

Revision as of 23:36, 28 April 2015

Introduction

To keep the code in your packages clear and manageable, it is advised to use an Integrated Development Environment (IDE) to edit your C++ code. Qt Creator is such an IDE for C++. It has the advantage of understanding you code up to some extend. This means Qt Creator can be used to, e.g., auto-complete names of variables and functions or get compilation error message in a nice way. Also, as was stated in the previous tutorial, it understands CMake, which allows it do be used to compile your project, and even run the resulting executables.

Installing Qt Creator

  1. Download Qt Creator for Linux:
  2. Open a terminal, cd to the folder where you downloaded the file (probably ~/Downloads)
  3. Make the file executable:
    chmod +x <INSTALL_FILE>
  4. Run the installation:
    ./<INSTALL_FILE>

If you installed Qt Creator in the default path, you can run it by calling:

~/qtcreator-3.3.2/bin/qtcreator

Use with ROS

Open an existing ROS package

  1. Make sure your package is in the ROS_PACKAGE_PATH, you can check this by navigating to your package using:
 roscd <your_package_name>
  1. Start Qt Creator
  2. File -> Open File or Project
  3. Navigate to and open the CMakeLists.txt file of your package
  4. Change the build directory into <YOUR_PACKAGE_DIR>/build (that is: a / instead of a -). Click 'Next'.
  5. Click 'Run CMake'. This will automatically look for and include dependencies in the manifest.xml file, see which .cpp files you use, etc, based on your CMakeLists.txt.
  6. Click 'Finish'

Try it with the ROS package you created in this tutorial.

Now you are ready to start developing your code. Pressing Ctrl-b will build the active project. If you change the manifest.xml or CMakeLists.txt file, you only have to run CMake again (Build -> Run CMake). After compiling your package, Qt will show the warnings and errors in a much more user friendly way then your terminal!

Show header files in the 'Projects View'

Qt Creator only shows your .cpp files in the 'Project View', which can be a bit of a nuisance. Often you would also like to see header files (.h) if you have them. To also show your header files, perform the following trick:

  1. Open CMakeLists.txt
  2. Add the following line before rosbuild_add_executable:
    file(GLOB_RECURSE HEADER_FILES include/*.h)
    This looks for all .h files in the include folder of your package, and stores them in the variable HEADER_FILES.
  3. Add ${HEADER_FILES} to your rosbuid_add_executable list. For example:
    rosbuild_add_executable(my_program src/program.cpp ${HEADER_FILES})
  4. Within Qt Creator, run CMake (Build -> Run CMake)

You should now be able to see all .h files in the include folder of your package.

Troubleshoot

CMake Error

If you try to open your project in Qt Creator and you get the following message when running CMake:

CMake Error: The current CMakeCache.txt directory <YOUR_PACKAGE>/build/CMakeCache.txt is different
than the directory <OTHER_DIR>/build where CMakeCache.txt was created. This may result in binaries
being created in the wrong place. If you are not sure, reedit the CMakeCache.txt

you have probably moved your package without cleaning it (make clean). This means the absolute paths that where generated during building do not make sense anymore. To solve this, do the following:

  • Clean your project, i.e., type make clean
  • Make sure there is no CmakeLists.txt.user in your package (it is auto-generated by Qt Creator and should not be on the SVN)
  • Try to open your project again


Alright! Time to do some actual simulation! Let's fire up the PICO simulator!