首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >C++预处理器意外编译错误

C++预处理器意外编译错误
EN

Stack Overflow用户
提问于 2009-02-19 23:55:58
回答 6查看 7.9K关注 0票数 3

请看以下文件:(这是一个完整的文件)

代码语言:javascript
复制
#ifndef TEES_ALGORITHM_LIBRARY_WRAPPER_H
#define TEES_ALGORITHM_LIBRARY_WRAPPER_H

#ifdef _TEES_COMPILE_AS_LIB
#include <dfa\Includes\DFC_algorithms.hpp>
#include <DFA\FuzzyClassifier\FuzzyAlgorithmIntialization\InitFuzzyAlgorithm.hpp>
typedef teesalgorithm::tees_fuzzy_algorithms algorithms_switchyard_class;
#else
#include <DFA\Includes\commercial_algorithms.hpp>
//An incomplete class to hide implementation
class algorithms_switchyard_class;
#endif

class AlgorithmLibraryWrapper {
algorithms_switchyard_class * algorithmPtr_;

typedef teesalgorithm::tees_paramObj paramObj_type;
typedef teesalgorithm::tees_errorObj errorObj_type;  
typedef teesalgorithm::tees_statusObj statusObj_type;
typedef teesalgorithm::tees_dataObj dataObj_type;
typedef teesalgorithm::tees_outputObj outputObj_type;

public:

AlgorithmLibraryWrapper(const std::string& sAlgName, paramObj_type& paramObj,     errorObj_type& errObj, statusObj_type& statusObj, const char* sFilePath);
static bool dataReader(const std::string& sFileName, dataObj_type& dataObj,     errorObj_type& errObj, statusObj_type& statusObj);
bool runalgorithm(const dataObj_type& dataObj, outputObj_type& outObj, errorObj_type& errObj, statusObj_type& statusObj); 
~AlgorithmLibraryWrapper();

};


#ifdef _TEES_USE_COMPILED_ALGORITHM_LIB
#   ifdef _MSC_VER
    #if _MSC_VER < 1400  // If VC 2003
        #ifdef _DEBUG
            #error No AlgorithmLibWrapper libraries compiled for this version of VC
        #else
            #error No AlgorithmLibWrapper libraries compiled for this version of VC
        #endif
    #elif defined(UNDER_CE)  // Win CE
        #ifdef _DEBUG
            #pragma comment( lib, "AlgorithmLibWrapperCEd" )
        #else
            #pragma comment( lib, "AlgorithmLibWrapperCE" )
        #endif
    #else  // If VC 2005
        #ifdef _DEBUG
            #pragma comment( lib, "AlgorithmLibWrapperd" )
        #else
            #pragma comment( lib, "AlgorithmLibWrapper" )
        #endif
    #endif
#endif 
#endif


#endif //TEES_ALGORITHM_LIBRARY_WRAPPER_H

我得到了以下错误,我不知道为什么。我还手动计算了预处理指令。

AlgorithmLibraryWrapper.hpp:10:1:未终止#ifdef AlgorithmLibraryWrapper.hpp:7:1:未终止#ifndef

我正在使用可怜的vxWorks gcc编译器。请告诉我是我的错还是编译器的错。

EN

回答 6

Stack Overflow用户

回答已采纳

发布于 2009-02-20 00:07:53

问题可能在于所包含的文件(如果实际存在未平衡的#if/#endif)。

我会尝试用另一个编译器进行预处理。你可以用gcc来做这件事,不管它不会编译。只要让gcc (或者MinGW,如果你在Windows上)并运行

代码语言:javascript
复制
cpp -Iinclude_direcories your_file

或者,如果你不喜欢gcc,得到MSVC快报版。同样,您可以对甚至不编译的代码进行预处理,因此不工作库等方面没有问题。

大多数编译器都有一个选项,它将为您提供来自预处理器的输出,这样您就可以检查它正在做什么。例如,

代码语言:javascript
复制
gcc -E file.c >file.preproc

将给出预处理的源代码,这样您就可以检查#if与#endif之间的平衡。

票数 4
EN

Stack Overflow用户

发布于 2009-02-20 00:08:49

据猜测,您的其中一个文件#(包括此文件中的文件)有一个不匹配的#ifdef/#endif对。您需要查看所有的文件(就像预处理程序所做的那样),而不仅仅是这个文件。

票数 3
EN

Stack Overflow用户

发布于 2009-02-20 00:48:21

正如其他人所指出的,这很可能是由于不匹配的包括警卫。

如果您所包含的文件在您的控制下(即不是第三方封闭源代码库的一部分),您可以考虑替换#ifndef et。阿尔。保护(用于防止多个包含)使用#杂注一次。这将消除出现预处理器指令不匹配的可能性。

有一点要注意的是,普拉格玛是不标准的,所以只有在编译器支持它的情况下,它才能工作。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/567788

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档