Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

two different libraries using the same name types

I am using two different c++ libraries. Both libraries use a name for a type, let's say, called fofo. In lib1.h:

typedef short fofo;

In lib2.h:

namespace LIB2
{

    typedef struct
    {
        uint16_t toto;    
    } fofo;
}
using LIB2::fofo;

I have a C++ project/VS 2008 that uses both libraries: when I do in my project

#include lib1.h

I get the error: error C2874: using-declaration causes a multiple declaration

I would like to use in my project both libraries but without making any change to these libraries. The only thing that I can modify is my VS2008 project. Thanks for your help!

like image 493
loisir1976 Avatar asked Oct 20 '25 04:10

loisir1976


1 Answers

this (dirty) workaround will probably work (depending how the headers are being used)

instead of including lib1.h directly ,wrap it by making a new headerfile

lib1wrapped.h

#define fofo fofo_wrap
#include "lib1.h" // OR <lib1.h>
#undef fofo
like image 55
engf-010 Avatar answered Oct 22 '25 18:10

engf-010