Compilation guides

One of the most common problems for linux starters and inexperienced programmers is not only how to write a piece of code to do a certain task, but how to compile the code that is based on a particular library. Now if you intend to combine few libraries under the same program things are getting harder.

This list here provides few examples about the compilation processes of various libraries I have used in the past.

Compiling & Building c++ application with Hdf5
A guide to Compile Parflow (Ubunty only)
Compile C++ pgojects with OpenSceneGraph
Compile code based on CGAL
Compile Trilinos

 

UPDATE:

If you look into the above posts you will soon find out why I started writing about compilation.

However since I first wrote about it, things have changed a lot. To be honest, I no longer attempt to build libraries as I mention above.

Instead I use vcpkg when developing for windows and Spack when developing for linux/clusters. With both systems, building any library and their dependencies is a matter of write few lines of code. Yet, from time to time there is a need for troubleshooting but you don’t get even close to the frustration of doing everything on your own.

Git basic commands

I have been using git for a while but not to often so as to remember all the commands. The goal the following list is to have a summary of the most frequently used by me Git commands.

Upload to remote repository

The process of updating a remote repository involves the following commands

will return a list of untracked changes

(Dont forget a space between add and the dot)

will add all untracked files, while

will add only the given file

In case there are files to delete from the repo the following command does the trick

while

will submit the files that have been added so far for upload but it will not upload anything yet.

This finally will update the remote repository.


 Download from remote repository

It is always a good idea before start working on a project to check if there are updates on the remote repository

and then

This will tell whether the local repository is behind.

In that case

will update the local repository


 Exclude files

Typically files which are created as part of compile process and depend on the operating or local system as well as autosaved files should not be uploaded to the remote repository.

To avoid this one can specify rules locally in the file

.git/info/exclude

For example to ignore mex object files we can add *.mex.

There is also the .gitignore option. This is good option when only few files need to be uploaded to the remote repo. One can exclude all files and the include the sources only. See this at the end of the page for example

However the gitignore can be a bit strange in case there are multiple folders in a project and selected files from each folder need to be tracked. Lets say there is a project with 2 folders folder1 folder2 and each folder contains source code with extension *.cpp and *.hpp and other files and folders like CMakeCache.txt CMakeFiles/ etc. and we need to track only the code. The .gitignore should look like this: 


 

Resolve Conflicts


It is possible that the git push command will refuse to upload the changes. This can happen when two people A and B modify the same file. If A uploads the changes first then git will refuse to push the changes of B.

In that case the B should do the following:

First the git pull –rebase will update the local repository. However there will be some conflicts. The git status command will tell which files contain the conflicts (see more detailed description here). Then B has to edit the files and resolve the conflicts. When its done B need to add the files with git add and finally

will complete the pull and the local branch will ready for git push.


 

Find the remote URL

 

Getting help

Last but not least for every command you can get help using the flag –help e.g.

Useful Linux commands

How to

1)  untar files:

see more

2) create desktop shortcut:

3) switch g++ compilers (assuming you have more than one)

see more

4) shutdown from terminal

5) find the ubuntu version

see more

6) Switching workspaces

While most Ubuntu users may know that ctrl+arrows is a quick way to navigate through the different workspaces, fewer may know that ctrl+shift+arrows is also transferring the currently active window to the new workspace.

7) Move files recursively

Lets suppose we want to move all files with *.bin suffix from the current directory to a different one (e.g. ../Results/). The following command does the trick

8) Setting up Swap space

This link has all one needs to configure a swap space