-1

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!

Boki
  • 193
  • 1
  • 3
  • 15
  • The obvious answer is that one of those header files that are included from `/home` make use of something from `` and `"minMathsForEPM.h"`, but fail to explicitly `#include` them themselves. Thusly, you are required to do it yourself. – Sam Varshavchik Dec 14 '16 at 01:22
  • @ Sam Varshavchik : the tricky thing is in the last paragraph, if in the "working code" (the second code) you add your program, then it doesn't work and all the errors are related to declarations of complex quantities. This doesn't happen when you compile it on Windows. – Boki Dec 14 '16 at 01:27
  • 1
    You still haven't explained what the "problem" is. In the grand scheme of things, reodering the include files is a trivial matter, that can be dispatched of in a few seconds. The "problem" appears to be solved already: reorder the include files. – Sam Varshavchik Dec 14 '16 at 01:30
  • @ Sam Varshavchik : true! I've added another explanation in the last paragraph. That is the essence of the problem. Please help. Thanks! – Boki Dec 14 '16 at 01:36
  • I'll see to add more explanations soon. Thanks @ Sam Varshavchik. – Boki Dec 14 '16 at 01:41
  • I repeat "you still haven't explained what the "problem" is". You found a compilation error that was solved by reordering the include files. Problem solved. Next question. – Sam Varshavchik Dec 14 '16 at 01:42
  • 1
    Boki, if you `g++ -E mysourcefile.cpp` (assuming g++ compiler because of centos) the compiler will spit out the results of the preprocessor instead of an executable which, combined with the compiler error you get with a regular build should help you get some insights into what really went wrong. For best results use the same compiler flags as the regular build. – user4581301 Dec 14 '16 at 02:23
  • @user4581301: thank for the advice, I'll try it. Anyway, I'll see to reformulate the question today. – Boki Dec 14 '16 at 17:03
  • @user4581301, the question is now reformulated and better reflect what the problem is. Thanks. – Boki Dec 14 '16 at 19:33
  • @SamVarshavchik : the question is now reformulated and better reflect what the problem is. Thanks. – Boki Dec 14 '16 at 19:33
  • @VladimirF: The old one is deleted. The reformulated question is quite different from the initial one. Thanks. – Boki Dec 14 '16 at 19:58
  • OK, but be aware that with multiple downvoted or deleted questions you are seriously risking getting a ban. That's why I recommend editing one question to a good shape before opening others. Read http://stackoverflow.com/help/question-bans – Vladimir F Героям слава Dec 14 '16 at 20:01
  • @VladimirF: Thanks – Boki Dec 14 '16 at 20:05
  • @user4581301: Thanks for the above advice. It gives somwhat better insight: for example, the error on line 27 where function std::complex Funct_SPINORBIT(...) is located, in the preprocessing file looks like std::_Complex Funct_SPINORBIT(...). Could this be the source of the error with complex values? – Boki Dec 14 '16 at 20:35

2 Answers2

1

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.

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
  • @ Ben Voigt : Thanks for the feedback Ben. If I remove **extern "C"** I get more errors. The additional ones are of the following type: 1) **error: previous declaration of 'float __complex__ lapack_make_complex_float(float, float)' with 'C++' linkage**. 2) **error: conflicts with new declaration with 'C' linkage** This is related to the following line in LapackE's header: lapack_complex_float lapack_make_complex_float( float re, float im ); – Boki Dec 14 '16 at 22:56
  • At this site, https://gcc.gnu.org/ml/libstdc++/2007-02/msg00168.html , it is said that "Currently C++ will not parse the syntax for C99 complex types and I know of know proposal to do so...". But the compilation works on Windows. – Boki Dec 14 '16 at 23:04
  • @ Ben Voigt : to add to my comment above, the additional errors are all related to the LapackE header files. – Boki Dec 14 '16 at 23:16
  • Could it be the version of GCC that I am using on Windows machine(4.9.4) vs. version on Linux machine (4.4.7)? – Boki Dec 14 '16 at 23:28
  • Is it the same version of the library headers? – Ben Voigt Dec 14 '16 at 23:31
  • @ Ben Voigt: Yes, it is the same version of the header files. – Boki Dec 14 '16 at 23:55
1

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

Community
  • 1
  • 1
Boki
  • 193
  • 1
  • 3
  • 15