tags:

views:

41

answers:

1

Hi, I'm working on a module which uses a shared library, which in turn has a static library linked to it. The shared library build works fine and generates a .so. When I try to use it in the module, I get a variety of errors, most of which are based on stl (stl collections to be specific), at the compilation stage. The errors look like:

In file included from /usr/include/c++/4.3/list:68,                             
                 from /home/gayan/LHIMo/LHI/src/CalcEngine/include/JuncNodeInfo.h:11,                                                                           
                 from /home/gayan/LHIMo/LHI/src/CalcEngine/include/RiverFlowParameter.h:11,                                                                     
                 from Main.cpp:11:                                              
/usr/include/c++/4.3/bits/stl_list.h:465:11: error: macro "catch" requires 3 arguments, but only 1 given

This is given in most places which use list, vector or map. Please help me to resolve this.

Sample code: "CalcEngine.h" in the library:

#ifndef LHI_CALCENGINE_H_
#define LHI_CALCENGINE_H_

extern "C"{
#include <matrix2.h>
}

class CalcEngine{

public:

protected:

};


#endif /* LHI_CALCENGINE_H_ */

Main.cpp in the application:

#include <iostream>
#include <CalcEngine.h>
#include <list>  // The compilation fails as soon as this is added

int main(int argc, char** argv){

    return -1;
}

I feel this has something to do with the matrix2.h file but could not pinpoint it. The file could be found here

+1  A: 

Doing some googling it seems like the Meschach library has a macro called catch (defined err.h indirectly included by matrix2.h) causing c++ code having exception catching to fail. Try

#undef catch 

after you are done including the meschach headers and see if works better.

Laserallan
Works like a charm. One more clarification: Do I have to use #undef every time I include a class which uses catch? Is there a better way to do this (i.e. undef catch globally)?
Gayan
Yes. Every time you directly or indirectly include err.h you'll need to undef catch. I recommend you to create a file called something like meschach.h and include all headers you need followed by #undef catch. Now you include this file instead of the specific headers to avoid problems.Another approach would be to see if you find a different library for your purpose that was written on this side of y2k. Even if it's a C library, it's really bad behavior to redefine catch. However it's a forgiving circumstance that the code is from 1993.
Laserallan
Just came across def for "max" which was messing with some other include files I was using :). I'll start looking for an alternative. I tried to contact the authors but the addresses given in the site aren't correct.Thanks a lot Laserallan. I don't think I'd have figured this out in a million years.
Gayan
You're welcome. Note that windows.h contains evil definitions of min and max so meschach is in good company :)
Laserallan