开发者

c++ include redeclaration

I have two libraries in my include path:

/usr/local/include开发者_开发技巧/lib1/
/user/include/lib2/

Both define a header file "vec.h" and I get the following error:

/usr/local/include/lib1/vec.h:22: error: redeclared with...

How to handle this?


You do:

#include "lib1/vec.h"
#include "lib2/vec.h"

Your makefile should then have include paths up to the lib1 and lib2.

-I /usr/local/include /user/include

You should ensure that the headers have guards around them to make sure they don't get declared twice. You should see something like:

#ifndef MYHEADER_H_ab2592zx1__
#define MYHEADER_H_ab2592zx1__

#include ...
#include ...
class ...

#endif

You should have these guards regardless of whether you have two includes of the same name and they should typically end with something fairly random in order to limit/lower the possibility that they conflict with a header guard in another file.


(Sorry, can't comment yet, so posting as an answer.) What exactly is at line 22 of lib1/vec.h and what is the complete error message? It looks like the header is trying to declare something that was already declared in a different way somewhere, which may even have nothing to do with lib2/vec.h.

EDIT

So you have a name clash. I don't know what library trimesh2/include/Vec.h belongs to (probably lib2), but the problem is definitely a conflict between this header and lib1/img.h. Two libraries define two different classes with the same name Vec. There is no solution to this problem unless you have sources of one of the libraries and are willing to rename one of Vecs to something else and recompile it. You just can't have two different things with the same name in one program.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜