So after I tried I went back to Yocto now it works. But I think it would be still useful to answer this question.
So you think that the version which is pre-installed in the distribution is too old too new? And what are ways to compile? I used the g++ compiler. Gcc doesn't change anything.
I do not know which version comes installed in the Ubilinux image, the latest MRAA version is 0.7.3 from intelgalactic/
In order to compile C or C++ code you need to link the MRAA library for example, if you are going to compile the blink-io.c example you need to run gcc blink-io.c -o output -lmraa . Sometimes you also need to indicate the location of the library when you compile the code with something like -I /usr/include