即使包含头文件,也会出现“不命名类型”错误

时间:2019-09-25 02:10:40

标签: c++ debugging compiler-errors

以下是我收到的错误消息:

enter image description here

这是“未命名类型错误”,通常发生在不包含头文件或头文件之间存在循环依赖性的情况下。

以下是据说导致错误的文件:

SparseGenRealShiftSolvePardiso.h的代码段:

#ifndef SPARSE_GEN_REAL_SHIFT_SOLVE_PARDISO_H
#define SPARSE_GEN_REAL_SHIFT_SOLVE_PARDISO_H

#include <SolverPardiso.h>
#include <Eigen/Core>
#include <Eigen/SparseCore>
#include <Eigen/SparseLU>
#include <stdexcept>

namespace Spectra {


///
/// \ingroup MatOp
///
/// This class defines the shift-solve operation on a sparse real matrix \f$A\f$,
/// i.e., calculating \f$y=(A-\sigma I)^{-1}x\f$ for any real \f$\sigma\f$ and
/// vector \f$x\f$. It is mainly used in the GenEigsRealShiftSolverPardiso eigen solver.
///
template <typename Scalar,int Flags = 0, typename StorageIndex = int>
class SparseGenRealShiftSolvePardiso
{
private:
    typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> Vector;
    typedef Eigen::Map<const Vector> MapConstVec;
    typedef Eigen::Map<Vector> MapVec;
    typedef Eigen::SparseMatrix<Scalar, Flags, StorageIndex> SparseMatrix;
    typedef const Eigen::Ref<const SparseMatrix> ConstGenericSparseMatrix;

    Eigen::SparseMatrix<double,Eigen::RowMajor> m_mat;
    const int m_n;
//    Eigen::SparseLU<SparseMatrix> m_solver;
//    SparseMatrix& m_mat;
    mutable SolverPardiso<Eigen::SparseMatrix<double,Eigen::RowMajor> > m_solver; // << THIS IS THE PROBLEM

TimeStepperEigenFitSI.h的摘要:

#ifndef TimeStepperEigenFitSI_h
#define TimeStepperEigenFitSI_h


#include <SolverPardiso.h>
#include <World.h>
#include <Assembler.h>
#include <TimeStepper.h>
#include <Eigen/Dense>
#include <Eigen/Sparse>
#include <UtilitiesEigen.h>
#include <UtilitiesMATLAB.h>
#include <Eigen/SparseCholesky>
#include <EigenFit.h>
#include <limits>
#include <Eigen/Eigenvalues>

#include <unsupported/Eigen/MatrixFunctions>

#include <math.h>
#include <algorithm>

EigenFit.h的摘要:

#ifndef EigenFit_h
#define EigenFit_h

#include <SolverPardiso.h>
#include <FEMIncludes.h>
#include <GaussIncludes.h>
#include <UtilitiesFEM.h>
#include <State.h>
#include <ParticleSystemIncludes.h>
#include <ConstraintFixedPoint.h>
#include <unsupported/Eigen/SparseExtra>
#include <sys/stat.h>
#include <igl/sortrows.h>
#include <igl/histc.h>
#include <igl/unique_rows.h>
#include <igl/hausdorff.h>
#include <fstream>
#include <SparseGenRealShiftSolvePardiso.h>

#include <igl/boundary_facets.h>
#include <resultsUtilities.h>

exampleEigenFit.cpp的代码段:

#include <functional>

#include <Qt3DIncludes.h>
#include <GaussIncludes.h>
#include <FEMIncludes.h>

//Any extra things I need such as constraints
#include <ConstraintFixedPoint.h>
#include <TimeStepperEigenFitSI.h>
#include <resultsUtilities.h>
#include <EigenFit.h>
#include <fstream>
#include <igl/boundary_facets.h>
#include <igl/volume.h>
#include <igl/writePLY.h>
#include <time.h>

#include <fstream>
#include <vector>
#include <cstdlib>
#include <iostream>

位于SolversLinear文件夹中的 SolverPardiso.h 的片段,如您从编译顺序中看到的,首先在exampleEigenFit.cpp之前进行编译:

#ifndef SolverPardiso_h // OLD
#define SolverPardiso_h

// #ifndef SolverPardiso // ADDED
// #define SolverPardiso // ADDED

#ifdef GAUSS_PARDISO

extern "C" void pardisoinit (void   *, int    *,   int *, int *, double *, int *);
extern "C" void pardiso     (void   *, int    *,   int *, int *,    int *, int *,
 double *, int    *,    int *, int *,   int *, int *,
 int *, double *, double *, int *, double *);
extern "C" void pardiso_chkmatrix  (int *, int *, double *, int *, int *, int *);
extern "C" void pardiso_chkvec     (int *, int *, double *, int *);
extern "C" void pardiso_printstats (int *, int *, double *, int *, int *, int *,
 double *, int *);


#include <cstdio>
#include <cstdlib>
#include <cmath>

template<typename MatrixType>
class SolverPardiso
{
public:
protected:
private:
};

template <>
class SolverPardiso<Eigen::SparseMatrix<double, Eigen::RowMajor> >
{
public:

    using SparseMatrix = Eigen::SparseMatrix<double, Eigen::RowMajor>;

    //Pardiso stuff
    //default matrix type = unsymmetric
    //only the upper triangle of symmetric matrices must be passed to pardiso 
    SolverPardiso(int matrixType = 11, unsigned int numProcessors = 8) {

        m_matrixType = matrixType;

        //Annoying license file stuff
        int error = 0;
        int solver = 0; /* use sparse direct solver */
        pardisoinit (m_ptr,  &m_matrixType, &solver, m_integerParams, m_doubleParams, &error);

        if (error != 0)
        {
            if (error == -10 )
                printf("No license file found \n");
            if (error == -11 )
                printf("License is expired \n");
            if (error == -12 )
                printf("Wrong username or hostname \n");
            exit(0);
        }
        else
            printf("[PARDISO]: License check was successful ... \n");

        //Number of Processors
        m_integerParams[2] = numProcessors;
        m_maxfct = 1; //perform at most one factorization
        m_mnum = 1; // use factorization 1
        m_nrhs = 1; //1 right hand side for now
        m_displayStats = 0;

    }

首先,将头文件SolverPardiso.h包含在SparseGenRealShiftSolvePardiso.h中,以便排除不包含头文件的情况,并基于头文件SolverPardiso.h,看起来仅在调用原始头文件,所以我不知道怎么可能有循环依赖。

如果代码太长且太复杂,我深表歉意。但是我已经坚持了一段时间。

谢谢。

0 个答案:

没有答案