How to setup Qt5 for Ubuntu using Virtual Box

From Qt Wiki
Jump to: navigation, search
IMPORTANT: The content of this page is outdated. Reason: Old versions of Qt, Ubuntu and Virtual Box
If you have checked or updated this page and found the content to be suitable, please remove this notice.

Introduction

Having struggled for a few days getting the correct sequence of events to occur to allow me to run Qt on a Ubuntu virtual machine on my window PC I feel I should share what I have found incase others want to do the same.

Why would you want to even do that? - well, in my case, I can now run my Qt project on Windows and Linux very easily and very quickly test it works for both. This provides quicker multi-platform testing. You can also test multiple versions of Ubuntu (or windows) and with different compiler versions as well, you just add more virtual machines.

Finally to be able to work / sync to the same code-base you can install/use rabbitVCS on Ubuntu so that it works in the same way as tortoise SVN in windows, and then all of your virtual machines are "talking" to the same SVN repo… nice :)

Versions

These are the versions that I have used / tested this all with Windows: XP SP3 (as my host operating system) Ubuntu: 10.04, 12.04 and 12.10 VirtualBox: v4.2.12

1. Setting Up VirtualBox with Ubuntu

In the purpose of this wiki I will use the example of Ubuntu 12.04 and make notes where other versions may differ.

Install and setup a virtual machine for Ubuntu:

  • Download and install VirtualBox latest version
  • Run virtual box and cklick "new"
  • Enter name and ensure "version" is Ubuntu. Go through the screens and select the following options:
  • at least 512MB (more if you can, allow about 1/4 of your memory).
  • Create virtual HDD
  • VDI
  • Dynamic or Fixed (I chose fixed because I heard there can be issues with running out of disk space with dynamic, but I am sure dynamic is probably ok!)
  • Allow at Enough space, the default is ok (8GB)…

Now your Virtual Machine is created. Do the following to install Ubuntu:

  • Download Linux .iso image from http://releases.ubuntu.com/precise/ (I put it on a USB stick)
  • Double click your fresh virtual machine called <name> (whatever you called it)
  • It will ask you to select a Startup disk. Click the browse button and select your .iso image. Now your ubuntu will boot from this image
  • Ubuntu will run, you will have two options: "Use Ubuntu" or "Install", click install and follow the installation process, I just used all the defaults (except for username, passwords, etc…).
  • Once this is completed you will reboot Ubuntu. If your virtual machine does not automatically restart, close it (shutdown) and re-start it in VirtualBox.
  • At this point your Ubuntu may boot and tell you that you are in "low graphics mode". Don't panic, just press ctrl+alt+f1 (left ctrl button) to go to the command line and continue with the following steps, otherwise you are done for this part :)
  • Login by entering your user name followed by your password.
  • Once you are logged in enter: "sudo apt-get update"
  • For "sudo" it will ask you for your password again, enter it.
  • Enter "sudo apt-get upgrade" to perform the upgrades.
  • Now enter "sudo reboot" to reboot, this should sort it.

Once you are in to ubuntu, you may want to install further updates from the update manager… or go into a terminal and run the previous 4 steps (except for the reboot part :o )

Now to make your Virtual Ubuntu experience even better (otherwise you are limited to a tiny window and have no copy/paste buffer or other shared resources, etc…

  • You need to install Guest Additions in your Virtual Machine. For Ubuntu there is a handy "install guest addtions" under the devices menu when you are running Ubuntu. Click this.
  • This copies some files to: /media/VBOXADDITIONS….
  • cd to this location
  • now run the linux additions: "./VBoxLinuxAdditions.run"
  • Once this is finished, restart your VMachine.

2. Installing Qt 5.0.2 on Ubuntu

Note: For the latest GNU compiler its probably worth getting the latest Ubuntu release (i.e. >= 12.10 for gcc/g++ 4.7 or higher for the c++11 features) rather then trying to upgrade the compiler and all the links/libraries yourself! I recommend Ubuntu 12.10 for the moment which give gnu 4.7.2, but this is all your choice…

  • download the latest (or whichever version you want) Qt sdk from qt.io/download (5.0.2 was used at the time of writing)
  • cd to the download directory and enter the following commands:
  • sudo chmod +x qt-linux-opensource-5.0.2-x86-offline.run (where this is the file you downloaded, this makes it eXecutable)
  • sudo ./qt-linux-opensource-5.0.2-x86-offline.run (to run it)
  • Follow the install instructions.

Now you have Qt 5.0.2, with Qt creator and all the tools to run and build your project. But since I documented RabbitVCS I may as well add that next…

3. RabbitVCS (a TortoiseSVN substitute for Ubuntu)

  • Enter the following in a terminal (enter password for first "sudo" command
  • sudo add-apt-repository ppa:rabbitvcs/ppa
  • sudo apt-get update
  • For Ubuntu >= 11.10: "sudo apt-get install rabbitvcs-thunar rabbitvcs-gedit rabbitvcs-cli rabbitvcs-nautilus3"
  • For Ubuntu < 11.10: "sudo apt-get install rabbitvcs-thunar rabbitvcs-gedit rabbitvcs-cli rabbitvcs-nautilus"
  • Now log out of Ubuntu and log back in for changes to take effect.

Note: To use, right click in any folder and do SVN —> Checkout…. the rest is pretty much the same as tortoiseSVN :) Or, you can use the command line :(

4. Trouble Shooting

This is a list of issues that I faced and how they where resolved, I will add to this list if I find more…

Ubuntu 12.04 has experienced an internal error with /usr/bin/Xorg

Re-start lightdm to clear the problem:

  • sudo service lightdm stop
  • sudo dpkg-reconfigure xorg xserver-xorg xserver-xorg-core
  • sudo service lightdm start

"/usr/bin/ld: cannot find -lgcc_s" when building your Qt project

In some later versions of Ubuntu some files seem to have moved or been renamed and we need to make a sym link to fix this (well, this is the easiest way to do it). Do this with the following line in a terminal:

  • sudo ln -s /lib/libgcc_s.so.1 /lib/libgcc_s.so

5. Final Note

Feel free to comment, add-to or correct this page :) … or even just laugh and say "look at this idiot there" :o

6. Related Articles