name conflict

J

John

I am using two large libraries which both have an implementation
of a "matrix" class. I have the source code for both.
I need to use them in the same project and when I try to compile
I get a double declaration conflict. I tried to wrap the smaller
library into a namespace but its a nightmare. Is there anyway
I could solve this problem without giving up on one of the libraries?

Thanks,
--j


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
 
J

Jack Klein

I am using two large libraries which both have an implementation
of a "matrix" class. I have the source code for both.
I need to use them in the same project and when I try to compile
I get a double declaration conflict. I tried to wrap the smaller
library into a namespace but its a nightmare. Is there anyway
I could solve this problem without giving up on one of the libraries?

Thanks,
--j

Yes, if you have the source code for both of them, do a search and
replace in one source code tree and change the conflicting name.

It's a bit of work, but this is only a real problem when you don't
have and can't get the source code.



[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
 
R

Rolf Magnus

John said:
I am using two large libraries which both have an implementation
of a "matrix" class. I have the source code for both.
I need to use them in the same project and when I try to compile
I get a double declaration conflict. I tried to wrap the smaller
library into a namespace but its a nightmare.

Why is that a nightmare?
Is there anyway I could solve this problem without giving up on one of the
libraries?

No standard C++ solution, AFAICS. Maybe there is something in your compiler
or linker that might help.


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
 
B

benben

John said:
I am using two large libraries which both have an implementation
of a "matrix" class. I have the source code for both.
I need to use them in the same project and when I try to compile
I get a double declaration conflict. I tried to wrap the smaller
library into a namespace but its a nightmare. Is there anyway
I could solve this problem without giving up on one of the libraries?

Thanks,

Option 1 Do not use them together. Look for alternative libraries. This
option is preferred when you have the freedom to choose between libraries.

Option 2 Use them separately. This means #include'ing header(s) of only
one of the conflicting libraries in any one translation units. This option
is preferred when the two conflicting libraries can be used in separate
places of your program, i.e. the uses of them are not intertwined.

Option 3 Provide wrapper classes/functions for one of the two libraries or
both. Put your own abstractions in separate namespaces and only #include the
troublesome library headers in the implementation of your own abstraction
layer (so by #including your own abstraction layer headers won't pull in the
library headers). This potentially can be expensive but it always works.

Ben





[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
 
A

albrecht.fritzsche

John said:
I am using two large libraries which both have an implementation
of a "matrix" class. I have the source code for both.
I need to use them in the same project and when I try to compile
I get a double declaration conflict. I tried to wrap the smaller
library into a namespace but its a nightmare.

Why is this a nightmare? Inserting in every header and source file
of both implementations

namespace SmallMatrix { // or namespace BigMatrix {

and

}

should be straigtforward, shouldn't it?

Ali

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
 
?

=?ISO-8859-15?Q?Andr=E9_Kempe?=

John said:
I am using two large libraries which both have an implementation
of a "matrix" class. I have the source code for both.
I need to use them in the same project and when I try to compile
I get a double declaration conflict. I tried to wrap the smaller
library into a namespace but its a nightmare. Is there anyway
I could solve this problem without giving up on one of the libraries?

Thanks,
--j
Are these libraries "headers-only" libraries like MTL?
Maybe a

namespace matrix_lib_1 {
#inlude "headers_of_lib_1.hpp"
}

could do it?

Andre

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
 
G

Greg

John said:
I am using two large libraries which both have an implementation
of a "matrix" class. I have the source code for both.
I need to use them in the same project and when I try to compile
I get a double declaration conflict. I tried to wrap the smaller
library into a namespace but its a nightmare. Is there anyway
I could solve this problem without giving up on one of the libraries?

Thanks,
--j

This is exactly the type of problem that C++ namespaces should be able
to handle. It's unclear what what part of the process turned into a
nightmare, or even how the name conflict manifests itself in the first
place. Does it cause a compiler error or just a linker error? Are both
matrix classes used in the source files, or is it an include file
problem? If both matrix classes are in use, does any single source file
use both?

Ideally, it should be possible to place both the interface and the
implementation of one of the libraries into a namespace. Just place a
"namespace MathLib { " at the top of the header and the source file and
a closing } at the end of both files (of course the namespace's name
doesn't have to be "Mathlib", in fact it's possible to alias
namespaces, so more than one name is possible). And although header
files should not have "using" directives that import names into the
global namespace; there is no problem importing global (or names from
other namespaces) into a namespace. Doing so may resolve difficulties
caused by having placed the interface into a namespace.

Greg


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
 
J

James Kanze

Jack said:
in comp.lang.c++:
Yes, if you have the source code for both of them, do a search
and replace in one source code tree and change the conflicting
name.

If you have the sources, wrapping one (or both) of them in a
namespace is fairly straight forward.
It's a bit of work, but this is only a real problem when you
don't have and can't get the source code.

If you don't have the sources, there's not really much you can
do.

--
James Kanze mailto: (e-mail address removed)
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 pl. Pierre Sémard, 78210 St.-Cyr-l'École, France +33 (0)1 30 23 00 34

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
 
W

werasmus

John said:
I am using two large libraries which both have an implementation
of a "matrix" class. I have the source code for both.
I need to use them in the same project and when I try to compile
I get a double declaration conflict. I tried to wrap the smaller
library into a namespace but its a nightmare. Is there anyway
I could solve this problem without giving up on one of the libraries?

namespace SmallLib{

#include <mySmallLib.h>

}//end namespace SmallLib

Hope this helps,

W

Thanks,
--j


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
 
K

kanze

[...]
Option 2 Use them separately. This means #include'ing
header(s) of only one of the conflicting libraries in any one
translation units. This option is preferred when the two
conflicting libraries can be used in separate places of your
program, i.e. the uses of them are not intertwined.

That's not necessarily sufficient. What happens if the two
classes both have defaut constructors, for example. The linker
will pull in at most one, and you'll end up with the constructor
for one of the classes invoked to construct instances of the
other.
Option 3 Provide wrapper classes/functions for one of the two
libraries or both. Put your own abstractions in separate
namespaces and only #include the troublesome library headers
in the implementation of your own abstraction layer (so by
#including your own abstraction layer headers won't pull in
the library headers). This potentially can be expensive but it
always works.

It shares the same problem with linking as the above.

It can be made to work if you put the two matrix classes in
separate dynamically loaded objects.

--
James Kanze GABI Software
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,270
Latest member
TopCryptoTwitterChannels_

Latest Threads

Top