views:

530

answers:

6

Please look at the following file: (it is a complete file)

#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

I am getting the following errors. I dont know why. I manually counted the preprocessor directives also.

AlgorithmLibraryWrapper.hpp:10:1: unterminated #ifdef
AlgorithmLibraryWrapper.hpp:7:1: unterminated #ifndef

I am using a stupid vxWorks gcc compiler. I think this compiler sucks. Please let me know whether I suck or this compiler.

+4  A: 

It could be that the problem is in the included files (if there actually are unbalaced #if/#endifs.

I would try preprocessing with another compiler. You can use gcc for that, doesn't matter it wouldn't compile. Just get gcc (or MinGW if you're on Windows) and run

cpp -Iinclude_direcories your_file

Or, if you don't like gcc, get MSVC Express edition. Again, you can preprocess code that even doesn't compile, so no problem with nonworking library etc.

Most compilers have an option that will give you the output from the preprocessor so you can check what it's doing. For example,

gcc -E file.c >file.preproc

will give you the pre-processed source so you can check the balancing of #if against #endif.

jpalecek
I don't count an excessive endif. They seem matched to me. The indentation of the big block is not to my liking, but still matched. If you're referring to the final endif, that's the include guard that was started at the top.
paxdiablo
No, I wasn't referring to the final on, but the prevoius. However, you're right it's correct
jpalecek
@jpalecek, "gcc -E" will generate the preprocessor output to stdout which you can check for balance. I added that in, hope you don't mind.
paxdiablo
+3  A: 

At a guess, one of the files you are #including from this one has a mismatched #ifdef/#endif pair. You need to look at all the files (as the preprocesor does), not just this one.

anon
Indeed, this is the case. Running `cpp` on this produces a clean file (without the includes, of course).
greyfade
Sorry, zabzonk, I had to take away my upvote since you removed the useful additions. I thought it important to mention how to do it, not just that it can be done. But, it's your answer, not mine.
paxdiablo
+1  A: 

As others have noted, this is most likely due to mismatched include guards.

If the files you are including are under your control (i.e. not part of a 3rd party closed source library), you could consider replacing the #ifndef et. al. guards (which are used to prevent multiple inclusion) with #pragma once. This will eliminate the possibility of having mismatched preprocessor directives.

One caveat of this is that pragma once is non-standard, so it will only work if your compiler supports it.

LeopardSkinPillBoxHat
A: 

I have tried to compile your source using vs 6.0 but did not get the error you have mentioned. As others said may be the error is coming from the included header file . For me to get your code compiled i need to comment the above header.

Please check the above header once.

coolcake
A: 

I'd debug this by commenting out sections one by one and trying to identify which section is causing the error.

It could be your compiler does not like the nested #ifdefs or does not interpret the syntax correctly. Maybe it doesn't like the #pragmas.

Adam Pierce
A: 

This is a long shot, but in your source file you have the following line:

#   ifdef _MSC_VER

where there is whitespace between the '#' character and the directive name (ifdef). This is valid in C/C++; however, it's not too commonly seen so I wouldn't be very surprised if the odd compiler choked on it.

Michael Burr