[Dune] How to force -std=c++0x in a dune project?

Arya Fallahi arya.fallahi at gmail.com
Sun Feb 17 21:54:24 CET 2013


Hi Markus,

Sorry, I did not thought about this aspect of the mailing list. So, I am
now writing about the problem and the solution I used for it in detail.
Actually, the problem may be trivial for you as computer scientists, but
took me as a physicist a long time to solve it.

I aimed using a separate installation of gcc on a machine for writing a
dune project, rather than the default one in linux. It is sometimes desired
since in this case you can work with your own gcc and problems appearing
from updating issue is avoided. For example, in my case I wanted to install
separate gcc because the default one was gcc-4.1.2 and the update feature
was turned off by the system administrator. A good benefit is that in this
case you can update your gcc always without disturbing any part of the
operating system. I did it in my AFS account and now I have the freedom to
bring my gcc to any machine and run it anywhere I like :-). Now the
question is what I needed to do.

First, I installed gcc with simple routines as the following:

tar xzf gcc-4.7.2.tar.gz
cd gcc-4.7.2
./contrib/download_prerequisites
cd ..
mkdir objdir
cd objdir
sudo ../gcc-4.7.2/configure --prefix=/tools/gcc-4.7.2 --program-suffix=-4.7
--build=x86_64-linux-gnu
make
sudo make install

It is recommended to use the program-suffix option to be able to
distinguish between the different gcc installation. Next, as it is often
recommended in gcc threads, I needed to add the path to bin folder to the
PATH variable and a similar thing for LD_LIBRARY_PATH. I wrote the
following lines in the .bashrc (.profile) file:

export PATH=/tools/gcc-4.7.2/bin:$PATH
export
LD_LIBRARY_PATH=/tools/gcc-4.7.2/lib:/tools/gcc-4.7.2/lib64:$LD_LIBRARY_PATH

This ensures that you find the installed gcc in terminal. By once closing
and opening a new terminal you will see that "gcc-4.7 --version" points to
the installed gcc. The same will be true also for g++-4.7, cpp-4.7 and
gfortran-4.7. HOWEVER, I realized that this is not enough for using this
gcc installation when dune is compiling. In fact, dune uses automake and it
seems automake just searches the directory /usr/bin (or /usr/local/bin) to
find the installed package. This caused me to receive an error "C compiler
not found" when I forced dune to compile with the installed gcc using the
CXX=g++-4.7 and CC=gcc-4.7 flags.

Without the mentioned flags, dune will be compiled using the default
installation without sending a notice. This was indeed what was happening
on my laptop with ubuntu. For 3 months it was using the default
installation 4.6.3 and I thought the installed 4.7.1 version is used. I
realized this when I tried to install on the server with a default version
4.1.2 which does not compile the dune code. The inability to compile, made
me investigate both config.log files and I saw none of the machines are
using the installed version. By the way, perhaps it is good to correct the
dune website, where the accepted version of gcc is written >=4.1. What I
know now is that gcc-4.1.2 does not accept -std=c++0x option and ends to
compilation errors.

The solution was to make a symbolic link in the /usr/bin folders to the
installed version, which means writing something like:

sudo ln -s /tools/gcc-4.7.2/bin/gcc-4.7 /usr/bin/gcc-4.7

and the same for g++, cpp and gfortran.

This makes the dune compiler finding and using the gcc-4.7.2 installation.
However, the libraries should also be linked to the compiler. As
recommended by the gnu compiler at the end of gcc make, I should add the
path to the libraries to the LD_LIBRARY_PATH, which is shown above and
additionally link to the used library in the linking flags. This part was
for me crucial and troublesome. In fact, using the linking flags to the
library always ended to using again the default installation and failing of
the compilation. Because automake overrides the libraries when it finds
similar ones. So, at the end always the default library was used. The
option for solving it is using the include folder in the compiler flags. I
just read in a thread that the include folders will not be overridden by
automake and once I write them, they are used. So, I did that and the
problem was solved. The ultimate opts file looks now as the following:

CONFIGURE_FLAGS=" MPICC='/tools/openmpi-1.6.3/bin/mpicc'
CC=gcc-4.7
CFLAGS='-O3 -g0 --no-strict-aliasing -I/opt/gcc-4.7.1/include'
CPP=cpp-4.7
CPPFLAGS='-O3 -g0 --no-strict-aliasing -I/opt/gcc-4.7.1/include'
CXX=g++-4.7
CXXFLAGS='-O3 -g0 --no-strict-aliasing -I/opt/gcc-4.7.1/include'
F77=gfortran-4.7
FFLAGS='-O3 -g0 --no-strict-aliasing -I/opt/gcc-4.7.1/include'
FC=gfortran-4.7
FCFLAGS='-O3 -g0 --no-strict-aliasing -I/opt/gcc-4.7.1/include'
--enable-parallel
--prefix='/tools/cyrus'
                  --with-metis='/tools/metis-5.0.2'
                  --with-alugrid='/tools/ALUGrid-1.52' "

I hope I was clear enough about the problems and did not use silly
solutions for them ;-).

In addition many thanks to you dune developers, specifically Markus and
Christoph for helping me with this issue,

Best regards,
Arya


On Sun, Feb 17, 2013 at 10:42 AM, Markus Blatt <markus at dr-blatt.de> wrote:

> Hi Arya,
>
> On Sun, Feb 17, 2013 at 07:09:17AM +0100, Arya Fallahi wrote:
> > Thank you very much for your kind help. I added the include directory to
> > the CPPFLAGS as well as other flags and it now compiles well.
> >
>
> ?????
>
> I fear that I do not understand what you did? Unfortunately, this
> probably means that others might have the same problem.
>
> Usually our help on this list should serve as guidelines to other
> people experiencing similar problems. In this thread one can neither see
> what the actual problem was nor what the actual solution was. Please
> tell the actual problem and solution next time and thus help make Open
> Source work!
>
> Cheers,
>
> Markus
>
> --
> Do you need more support with DUNE or HPC in general?
>
> Dr. Markus Blatt - HPC-Simulation-Software & Services
> http://www.dr-blatt.de
> Hans-Bunte-Str. 8-10, 69123 Heidelberg, Germany
> Tel.: +49 (0) 160 97590858  Fax: +49 (0)322 1108991658
>
> _______________________________________________
> Dune mailing list
> Dune at dune-project.org
> http://lists.dune-project.org/mailman/listinfo/dune
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.dune-project.org/pipermail/dune/attachments/20130217/778041f1/attachment.htm>


More information about the Dune mailing list