c++ - 在 Visual Studio 2010 的 C++ 中使用 lapack C header 的错误

标签 c++ c visual-studio-2010 lapack lapacke

请帮帮我!我花了几个小时在互联网上查找,但我还没有找到解决方案....

我正在尝试使用 C++ 函数中的 call lapack 函数,但一开始就失败了。这是我的代码:

#include "stdafx.h"
#include "targetver.h"
extern "C" {
#include "lapacke.h"
}


int main{}
{
    return 0;
}

我知道“lapacke.h”是一个 C 头文件,所以我使用了 extern "C" 子句。但是当我尝试编译这个微不足道的函数时,出现了以下错误:

Error   1   error C2146: syntax error : missing ';' before identifier 'lapack_make_complex_float'   c:\users\svd_example1\example2\example2\lapacke.h   89  1   example2
Error   2   error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   c:\users\svd_example1\example2\example2\lapacke.h   89  1   example2

有谁知道是什么导致了这些错误?

非常感谢!

最佳答案

header 的相关部分是:

/* Complex types are structures equivalent to the
* Fortran complex types COMPLEX(4) and COMPLEX(8).
*
* One can also redefine the types with his own types
* for example by including in the code definitions like
*
* #define lapack_complex_float std::complex<float>
* #define lapack_complex_double std::complex<double>
*
* or define these types in the command line:
*
* -Dlapack_complex_float="std::complex<float>"
* -Dlapack_complex_double="std::complex<double>"
*/

/* Complex type (single precision) */
#ifndef lapack_complex_float
#include <complex.h>
#define lapack_complex_float    float _Complex
#endif

/* ... */    

lapack_complex_float lapack_make_complex_float( float re, float im );

这默认使用 C99 _Complex,Visual C++ 不支持。您可以按照建议定义那些宏,以使用 std::complex 代替,Visual C++ 支持这些宏:

#include <complex>
#define lapack_complex_float std::complex<float>
#define lapack_complex_double std::complex<double>
#include "lapacke.h"

关于c++ - 在 Visual Studio 2010 的 C++ 中使用 lapack C header 的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24853450/

相关文章:

c++ - 如何从 QTreeView 返回节点名称

c# - 在 Visual Studio 2010 中保存 .ASCX 文件需要 3 分钟

c# - 在 C# 中从匿名类型生成类

visual-studio-2010 - 我在 Visual Studio 中丢失了数据集 Pane

c++ - 将 "ddd"附加到远程计算机上运行的进程

c++ - 动态分配中的内存地址

c - 单词长度直方图练习提示?

c - 在符合 MISRA 的情况下在 C 中传递缓冲区

c - 如何计算数组的移动平均值?

c++ - Qt 样式表是做什么用的,它们是如何工作的?