C++/LapackE code compiling fine on Windows, but the identical code fails compilation on Linux

290 views Asked by At

The code written in C++ with LapackE and MPI libraries compiles and runs great on Windows where I use GNU C++ 4.9.2.

Migrating that code to Linux (CentOS) server fails to compile! The GNU C++ on Linux machine is 4.4.7. I used identical LapackE header files in both cases. MPI works well on the Linux machine.

Upon inspection of preprocessor output files on both machines, I can relate the error messages to following situations where complex declarations in the original code were replaced by _Complex. Here is an example of a declaration of a complex dynamic array HAMILTONIAN that has problem when compiled on Linux:

IN THE ORIGNIAL SOURCE: lapack_complex_double* HAMILTONIAN;

IN THE WINDOWS PREPROC. FILE (works well): _lapack_complex_double* HAMILTONIAN;

IN THE LINUX PREPROC. FILE (fails to compile): double _Complex* HAMILTONIAN;

Could this be problem related to different versions of GCC?

I've tried #define _Complex complex but it's didn't help in the end.

Some reported problem with interoperability of C99 _Complex and C++ complex: possible similar problem.

Please help. Thanks!

2

There are 2 answers

0
Boki On BEST ANSWER

First, set GCC compiler to 4.8 or above: In my case, we had to keep the old GCC 4.4.7 and concurrently install GCC 4.9.2. To be able to use the newer version in MPI compilation, one has to add it to the front of the PATH. For that see the answer at How to change default GCC compiler to be used with MPI on Linux CentOS

Second, when compiling with LapackE (Lapack's wrapper for C) one has to use following preprocessor options (-D):

-D LAPACK_COMPLEX_STRUCTURE -D HAVE_LAPACK_CONFIG_H -D ADD_

Example:

bash-4.1$ mpiCC main.cpp -L/home/USER1/lapack-3.6.1 -llapacke -llapack -lblas -lm -Wall -D LAPACK_COMPLEX_STRUCTURE -D HAVE_LAPACK_CONFIG_H -D ADD_

Make sure that:

bash-4.1$ gcc --version

gives 4.8 or higher. In my case it was: gcc (GCC) 4.9.3

6
Ben Voigt On

it compiles OK even if I remove "extern "C" and just keep the #include "Headers_LAPACKE/..." in block#1 of the code.

Do this. The LAPACK headers have #if __cplusplus checks within them, they are designed so that the user code does not need, and should not have, extern "C" surrounding them.