-
Notifications
You must be signed in to change notification settings - Fork 8
Linux development environment
I believe the lack of IDE in Linux is because of its Unix ancestor:
Unix is a family of multitasking, multi-user computer operating systems that derive from the original AT&T Unix, development starting in the 1970sUnix systems are characterized by a modular design that is sometimes called the "Unix philosophy". This concept entails that the operating system provides a set of simple tools that each performs a limited, well-defined function, with a unified filesystem (the Unix filesystem) as the main means of communication, and a shell scripting and command language (the Unix shell) to combine the tools to perform complex workflows. See https://en.wikipedia.org/wiki/Unix
As a result, Linux tends to rely on the scripting languages and filesystem to integrate the different tools. If don't know yet how to make yourself comfortable with Vim and Gdb, then see how Linux is an IDE (all of it).
First things first, you need to install your development environment to fetch, build and launch the project.
This is the official package manager of Debian spin-off distributions like Ubuntu or Raspbian. Most popular applications are distributed through it and it is most usually pre-installed.
It is a good practice to update and upgrade it before installing more stuff:
sudo apt-get update
sudo apt-get upgrade
sudo apt-get autoremove
sudo apt-get clean
Commands:
-
update
- Updates the package lists for upgrades for packages that need upgrading, as well as new packages that have just come to the repositories. -
upgrade
- Fetches new versions of packages existing on the machine if apt knows about these new versions by way of the previous .update
command -
autoremove
- removes unused dependencies, packages which were installed by other packeges but which are no longer needed by your system. -
clean
- removes all the packages in the apt cache
See more about this:
- https://raymii.org/s/tutorials/Debian-apt-get-dpkg-packages-cleanup-commands.html
- https://askubuntu.com/questions/222348/what-does-sudo-apt-get-update-do
In a Linux distribution there is the highest chance that pkg-config is already installed. Still, you better be sure; should it be already installed it will just tell you:
sudo apt-get install pkg-config
To verify the installation, and seeing a list with all available packages:
pkg-config --list-all
Gtkmm is the Gtk for C++:
sudo apt-get install libgtkmm-3.0-dev
To check if the library is available as a dependency:
pkg-config --list-all | grep gtkmm
gtkmm-3.0 gtkmm - C++ binding for the GTK+ toolkit
You will need it to compile OpenCV, so you better install it now:
sudo apt-get install cmake
To verify that CMake is installed correctly:
cmake --version
Be sure to install Gtk3 before compiling OpenCV. If you don't, the CMake configuration links to Gtk2, and ends up in conflict as this project uses Gtk3.
As a prerequisite, you need to have the following libraries from apt-get:
# required:
sudo apt-get install \
libgtk-3-dev \
pkg-config \
libavcodec-dev \
libavformat-dev \
libswscale-dev
# Optional:
sudo apt-get install \
python-dev \
python-numpy \
libjpeg-dev \
libpng-dev \
libtiff-dev \
libjasper-dev \
libdc1394-22-dev
Once you've installed all prerequisites, fetch the sources of the latest release of OpenCV from the official repository at github, and unzip it:
wget https://github.com/opencv/opencv/archive/4.0.1.zip
unzip 4.0.1.zip
Prepare and compile:
cd opencv-4.0.1
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX=/usr/local ..
make -j2 # Number of processors. Don't use more that you computer has.
Go for a walk; this takes ages. If process breaks, you can launch again by just retyping:
make -j2
When compilation is done, complete the installation:
sudo make install
sudo ldconfig
You can now delete the sources folder; you don't need it any more:
cd ..
cd ..
rm -rf opencv-3.4.1
rm 3.4.1.zip
To install Git:
sudo apt-get install git
And to verify that Git is present:
git --version
> git version 2.7.4
Clone the example project (if needed, replace the URL in the git clone
command with the project of your choice), configure it with debug symbols, build it, and launch it.
cd go-to-your-working-folder
git clone https://github.com/raspberry-cpp-tutorials/gtk-opencv-simple.git
cd gtk-opencv-simple.git
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Debug ../src
make
./rascapp
I hope you don't need this section
By default, Git doesn't store your credentials, so you need to type them over and over each time you push
something. It is secure, but annoying. Git offers a set of credential-store
commands to control how and when you have to log in:
-
git config credential.helper store
- Stores your credentials once for all, in a file called~/.git-credentials
. It is very comfortable, but a security issue because the file is not encrypted. -
git config credential.helper "cache --timeout 7200"
- Caches your credentials for the specified amount of seconds (here it is 2 hours). Afterwards, or when you close your session, your credentials are forgotten. -
git config --unset credential.helper
- Removes the credential configuration. Don't forget to manually remove~/.git-credentials
.
I personally prefer the cache solution, as it is safer and already quite painless.
Read more about this: