LAPACKE/GNU C++ code fails to compile on LINUX but ok on WIN

Post here if you have a question about linking your program with LAPACK or ScaLAPACK library

LAPACKE/GNU C++ code fails to compile on LINUX but ok on WIN

Postby Boris_MV » Thu Dec 15, 2016 9:03 pm


I've developed code in C++ with LAPACKE and MPI on a Windows machine where the code compiles and works well. When I migrated the code to Linux(CentOS) server, the code failED to compile! The possible culprit is complex values declaration (in various forms). Details are listed below, please help!

--The code works well on Windows with GNU C++ version 4.9.2., Lapack/LAPACKE and MS MPI (MPICH2).

--The code does NOT compile on CentOS LINUX server. GNU C++ version is 4.4.7; MPI(MPICH2) works well on this Linux machine (tested with C++ codes without LAPACKE). The LAPACKE libraries I use on Windows are the same ones I use on Linux.

The errors I get when compiling on the Linux machine are related to declarations of complex values (scalars, arrays), and typically they are like this one error: expected unqualified-id before '__complex__'. Upon inspecting preprocessor output on both Win and Linux machines, I've noticed following (for example):

    If in the original source code you have declaration lapack_complex_double* HAMILTONIAN;, then
    on the Windows machine you would see _lapack_complex_double* HAMILTONIAN; (which works well on Windows) and
    on the Linux machine you would see double _Complex* HAMILTONIAN; which consequently gives error message during compilation stage.

More generally, I can see that the reported compilation errors on the Linux machine are pointing to places where complex in the original source is translated as _Complex in the preprocessor file, for the case of ordinary C++ variable; and for the case of LAPACKE variables when lapack_complex_double in the original source is translated as double _Complex. So, it seems like the problem is that compiler wrongly translates complex C++ type and similar LAPACKE types like lapack_complex_double[\b]. I've tried [b]#define _Complex complex , but (as expected) it didn't work - it solved problems on some places and created new problems on the other places.

Did you have experience with THE SAME or SIMILAR problem? Please help.

Thanks so much.
Posts: 7
Joined: Fri Dec 19, 2014 9:39 pm

Re: LAPACKE/GNU C++ code fails to compile on LINUX but ok on

Postby Julien Langou » Fri Dec 16, 2016 4:36 am

No expert in all this, but the lines
_lapack_complex_double* HAMILTONIAN;
double _Complex* HAMILTONIAN;
do not read to LAPACK to me. So I guess you have a second package involved in the mix.

I assume you are using LAPACK inside another specialized package and I would say that the problem comes at the interface of this package and LAPACK.

LAPACK has complex numbers defined as lapack_complex_double on Windows and so it seems that complex numbers are defined as lapack_complex_double for `HAMILTONIAN`. And so it works fine on Windows.

Then on Linux, it seems that LAPACK's complex numbers are defined as lapack_complex_double, while defined as _Complex* for `HAMILTONIAN`, and so this crashes.

I think you will need to set some compilation flags in the second package, maybe edit the code, so that this matches.

Julien Langou
Posts: 810
Joined: Thu Dec 09, 2004 12:32 pm
Location: Denver, CO, USA

Re: LAPACKE/C++ code fails to compile on LINUX but ok on WIN

Postby Boris_MV » Fri Dec 16, 2016 6:32 pm

Thanks Julien for your input. Here is my current update on this problem.

The issue is most likely in declarations of C vs. C++ complex entities. On this link ... -same-file it is said that "g++ does since 4.8 to support both <complex> and <complex.h> in the same translation unit." I think that is the issue here. I've tried #define complex _Complex but it creates more errors than it resolves. The GCC on the CentOS machine is ver. 4.4.7 and the one where I developed the code (Windows machine) is 4.9.2. The request has been put to the root/admin to updated the GCC on CentOS. I'll post the results once that is done.
In the meantime, if you or anyone reading had more ideas/info about this issue, I would greatly appreciate to post it here.
Have a nice weekend!!!
Posts: 7
Joined: Fri Dec 19, 2014 9:39 pm

Return to Linking Problem

Who is online

Users browsing this forum: No registered users and 2 guests