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

戏子无情 提交于 2019-12-08 14:02:48

问题


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!


回答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.




回答2:


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



来源:https://stackoverflow.com/questions/41133269/c-lapacke-code-compiling-fine-on-windows-but-the-identical-code-fails-compila

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!