Intel one-api 编译器在编译 GDAL cpp 文件时出错

Posted

技术标签:

【中文标题】Intel one-api 编译器在编译 GDAL cpp 文件时出错【英文标题】:Intel one-api compiler errors in compiling GDAL cpp files 【发布时间】:2021-06-23 14:19:33 【问题描述】:

我的目标是将 gdal cpp 文件编译为编译水文模型的一个小阶段。为此,我在 Ubuntu 上安装了 Intel OneAPI 基础工具包。使用它的编译器 icpx,我尝试编译 gdal cpp 文件。但是,它会引发与找不到头文件和从这些头文件中读取所需类相关的错误。所有头文件都包含在 cpp 文件中,并且它们完全位于 cpp 文件的同一目录中。任何帮助将不胜感激。

 icpx /media/sf_Share/IMWEBsModel/imwebs_Linux/WetSpaInterface2/gdal/gdal-3.3.0/port/cpl_error.cpp -Imedia/sf_Share/IMWEBsModel/imwebs_Linux/WetSpaInterface2/gdal/gdal-3.3.0/port '''

错误:

media/sf_Share/IMWEBsModel/imwebs_Linux/WetSpaInterface2/gdal/gdal-3.3.0/port/cpl_error.cpp:1341:17: error: use of undeclared identifier 'CPLErrorHandlerAccumulatorStruct'; did you mean 'CPLErrorHandlerAccumulator'?
    std::vector<CPLErrorHandlerAccumulatorStruct>* paoErrors =
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                CPLErrorHandlerAccumulator
/media/sf_Share/IMWEBsModel/imwebs_Linux/WetSpaInterface2/gdal/gdal-3.3.0/port/cpl_error.cpp:1338:18: note: 'CPLErrorHandlerAccumulator' declared here
void CPL_STDCALL CPLErrorHandlerAccumulator( CPLErr eErr, CPLErrorNum no,
                 ^
/media/sf_Share/IMWEBsModel/imwebs_Linux/WetSpaInterface2/gdal/gdal-3.3.0/port/cpl_error.cpp:1341:52: error: use of undeclared identifier 'paoErrors'
    std::vector<CPLErrorHandlerAccumulatorStruct>* paoErrors =
                                                   ^
/media/sf_Share/IMWEBsModel/imwebs_Linux/WetSpaInterface2/gdal/gdal-3.3.0/port/cpl_error.cpp:1342:26: error: no template named 'vector' in namespace 'std'
        static_cast<std::vector<CPLErrorHandlerAccumulatorStruct> *>(
                    ~~~~~^
/media/sf_Share/IMWEBsModel/imwebs_Linux/WetSpaInterface2/gdal/gdal-3.3.0/port/cpl_error.cpp:1342:33: error: use of undeclared identifier 'CPLErrorHandlerAccumulatorStruct'; did you mean 'CPLErrorHandlerAccumulator'?
        static_cast<std::vector<CPLErrorHandlerAccumulatorStruct> *>(
                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                CPLErrorHandlerAccumulator
/media/sf_Share/IMWEBsModel/imwebs_Linux/WetSpaInterface2/gdal/gdal-3.3.0/port/cpl_error.cpp:1338:18: note: 'CPLErrorHandlerAccumulator' declared here
void CPL_STDCALL CPLErrorHandlerAccumulator( CPLErr eErr, CPLErrorNum no,
                 ^
/media/sf_Share/IMWEBsModel/imwebs_Linux/WetSpaInterface2/gdal/gdal-3.3.0/port/cpl_error.cpp:1344:5: error: use of undeclared identifier 'paoErrors'
    paoErrors->push_back(CPLErrorHandlerAccumulatorStruct(eErr, no, msg));
    ^
/media/sf_Share/IMWEBsModel/imwebs_Linux/WetSpaInterface2/gdal/gdal-3.3.0/port/cpl_error.cpp:1344:26: error: use of undeclared identifier 'CPLErrorHandlerAccumulatorStruct'; did you mean 'CPLErrorHandlerAccumulator'?
    paoErrors->push_back(CPLErrorHandlerAccumulatorStruct(eErr, no, msg));
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                         CPLErrorHandlerAccumulator
/media/sf_Share/IMWEBsModel/imwebs_Linux/WetSpaInterface2/gdal/gdal-3.3.0/port/cpl_error.cpp:1338:18: note: 'CPLErrorHandlerAccumulator' declared here
void CPL_STDCALL CPLErrorHandlerAccumulator( CPLErr eErr, CPLErrorNum no,
                 ^
/media/sf_Share/IMWEBsModel/imwebs_Linux/WetSpaInterface2/gdal/gdal-3.3.0/port/cpl_error.cpp:1348:6: error: variable has incomplete type 'void'
void CPLInstallErrorHandlerAccumulator(std::vector<CPLErrorHandlerAccumulatorStruct>& aoErrors)
     ^
/media/sf_Share/IMWEBsModel/imwebs_Linux/WetSpaInterface2/gdal/gdal-3.3.0/port/cpl_error.cpp:1348:45: error: no member named 'vector' in namespace 'std'
void CPLInstallErrorHandlerAccumulator(std::vector<CPLErrorHandlerAccumulatorStruct>& aoErrors)
                                       ~~~~~^
/media/sf_Share/IMWEBsModel/imwebs_Linux/WetSpaInterface2/gdal/gdal-3.3.0/port/cpl_error.cpp:1348:52: error: use of undeclared identifier 'CPLErrorHandlerAccumulatorStruct'; did you mean 'CPLErrorHandlerAccumulator'?
void CPLInstallErrorHandlerAccumulator(std::vector<CPLErrorHandlerAccumulatorStruct>& aoErrors)
                                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                                   CPLErrorHandlerAccumulator
/media/sf_Share/IMWEBsModel/imwebs_Linux/WetSpaInterface2/gdal/gdal-3.3.0/port/cpl_error.cpp:1338:18: note: 'CPLErrorHandlerAccumulator' declared here
void CPL_STDCALL CPLErrorHandlerAccumulator( CPLErr eErr, CPLErrorNum no,
                 ^
/media/sf_Share/IMWEBsModel/imwebs_Linux/WetSpaInterface2/gdal/gdal-3.3.0/port/cpl_error.cpp:1348:87: error: use of undeclared identifier 'aoErrors'
void CPLInstallErrorHandlerAccumulator(std::vector<CPLErrorHandlerAccumulatorStruct>& aoErrors)
                                                                                      ^
/media/sf_Share/IMWEBsModel/imwebs_Linux/WetSpaInterface2/gdal/gdal-3.3.0/port/cpl_error.cpp:1348:96: error: expected ';' after top level declarator
void CPLInstallErrorHandlerAccumulator(std::vector<CPLErrorHandlerAccumulatorStruct>& aoErrors)
                                                                                               ^
                                                                                               ;
12 errors generated.
'''

更新: 更多说明:主 cpp 程序具有以下类:

static
void CPL_STDCALL CPLErrorHandlerAccumulator( CPLErr eErr, CPLErrorNum no,
                                              const char* msg )

    std::vector<CPLErrorHandlerAccumulatorStruct>* paoErrors =
        static_cast<std::vector<CPLErrorHandlerAccumulatorStruct> *>(
            CPLGetErrorHandlerUserData());
    paoErrors->push_back(CPLErrorHandlerAccumulatorStruct(eErr, no, msg));



void CPLInstallErrorHandlerAccumulator(std::vector<CPLErrorHandlerAccumulatorStruct>& aoErrors)

    CPLPushErrorHandlerEx( CPLErrorHandlerAccumulator, &aoErrors );


void CPLUninstallErrorHandlerAccumulator()

    CPLPopErrorHandler();

在这个类中,它尝试调用 CPLErrorHandlerAccumulatorStruct ,这是头文件中的另一个类 cpl_error_internal ,它包含在主 cpp 文件的开头 -->

#include "cpl_error_internal.h"

我猜的问题是主程序找不到头文件! while 1) 包含 2) 目录没有问题。

【问题讨论】:

看起来您使用的是CPLErrorHandlerAccumulator*Struct* 而不是CPLErrorHandlerAccumulator,并且您缺少#include &lt;vector&gt;。至少。 您还在cpl_error.cpp:1348 行的末尾缺少;。其余的错误应该通过修复这 3 个来解决。 @rturrado 非常感谢,你能看到更新吗? 嗯...我认为第二行 include &lt;cpl_error_internal.h&gt; 不应该在那里。如果CPLErrorHandlerAccumulatorStruct确实存在,并且你想在cpp文件中使用它,你需要知道它在cpp文件中声明在哪个头(可能是cpl_error_internal.h)和#include "cpl_error_internal.h" @rturrado 谢谢!我删除了,但错误没有变化 【参考方案1】:

我认为您没有正确配置 gdal。在编译代码之前,尝试在 gdal 主目录中使用 ./configure 命令配置 gdal 这样做之后,正确配置端口目录,因为如果您没有正确配置它,则会出现与“paoErrors”等未声明标识符相关的错误,而只是尝试编译'port'目录中的文件。

【讨论】:

以上是关于Intel one-api 编译器在编译 GDAL cpp 文件时出错的主要内容,如果未能解决你的问题,请参考以下文章

VS2008编译GDAL 1.8.1(转)

使用nmake编译Gdal源代码(Win10+VS2022)

gdal编译

GDAL2.0编译——32位和64位

GEOS/GDAL 交叉编译ARM64-linux版本

GDAL源码编译(32位)