c中类型的重新定义,但是否包括防护装置?

c中类型的重新定义,但是否包括防护装置?,c,header-files,C,Header Files,我有我不能在一台计算机上编译的代码。它在我的电脑上工作,但在另一台电脑上不工作。错误是“重新定义typdef cplx”,尽管我对每个头文件都有保护,对typdef的每个定义都有保护: #ifdef __cplusplus #include <complex> #include <cmath> typedef std::complex<double> cplx; #else #include <tgmath.h> typedef double co

我有我不能在一台计算机上编译的代码。它在我的电脑上工作,但在另一台电脑上不工作。错误是“重新定义typdef cplx”,尽管我对每个头文件都有保护,对typdef的每个定义都有保护:

#ifdef __cplusplus
#include <complex>
#include <cmath>
typedef std::complex<double> cplx;
#else
#include <tgmath.h>
typedef double complex cplx;
#endif
\ifdef\uuucplusplus
#包括
#包括
typedef-std::复杂cplx;
#否则
#包括
typedef双复数cplx;
#恩迪夫
为什么会出现这种问题? 这里有两个头文件。布拉斯h:

#ifndef BLAS_H
#define BLAS_H
#ifdef __cplusplus
#include <complex>
#include <cmath>
typedef std::complex<double> cplx;
#else
#include <tgmath.h>
typedef double complex cplx;
#endif
//declaration of functions
#endif
\ifndef BLAS\H
#定义BLAS_H
#ifdef_uucplusplus
#包括
#包括
typedef-std::复杂cplx;
#否则
#包括
typedef双复数cplx;
#恩迪夫
//职能声明
#恩迪夫
和lapack.h:

#ifndef LAPACK_H
#define LAPACK_H
#ifdef __cplusplus
#include <complex>
#include <cmath>
typedef std::complex<double> cplx;
#else
#include <tgmath.h>
typedef double complex cplx;
#endif
//declarations of functions
#endif
\ifndef LAPACK\H
#定义LAPACK_H
#ifdef_uucplusplus
#包括
#包括
typedef-std::复杂cplx;
#否则
#包括
typedef双复数cplx;
#恩迪夫
//职能声明
#恩迪夫

问题是当我同时包含lapack.h和blas.h时,我会得到这个错误吗

您的防护可以防止同一个include文件被包含两次,但是您有两个不同的包含文件和两个不同的防护,并且您可以在每个文件中定义
cplx

对于每个包含文件中的该类型,您需要单独的保护,如下所示:

#ifndef CPLX
#define CPLX
#ifdef __cplusplus
#include <complex>
#include <cmath>
typedef std::complex<double> cplx;
#else
#include <tgmath.h>
typedef double complex cplx;
#endif
//declarations of functions
#endif
#ifndef CPLX
#定义CPLX
#ifdef_uucplusplus
#包括
#包括
typedef-std::复杂cplx;
#否则
#包括
typedef双复数cplx;
#恩迪夫
//职能声明
#恩迪夫

给定的示例中实际上没有:)。我在头文件中包含了防护。因此,每个头文件在开始时都包含guard。此外,我还包括了对类型定义的保护。(如上面的代码所述)。@user3616359显示头文件的代码。通常,当编译器发出关于重新定义的警告时,它会显示错误发生的行号,以及先前定义的文件/行。是。它在包含lapack.h的行中给出,然后说它是在包含blas.h之前定义的。但是有了这些警卫,这不应该发生。