473,385 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

name conflict

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! ]

Oct 1 '05 #1
9 2310
John wrote:
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! ]

Oct 1 '05 #2
On 30 Sep 2005 21:55:24 -0400, "John" <we**********@yahoo.com> wrote
in comp.lang.c++:
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.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html

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

Oct 1 '05 #3

"John" <we**********@yahoo.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
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! ]

Oct 2 '05 #4
John wrote:
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! ]

Oct 2 '05 #5

John wrote:
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! ]

Oct 2 '05 #6
John schrieb:
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! ]

Oct 2 '05 #7
Jack Klein wrote:
On 30 Sep 2005 21:55:24 -0400, "John" <we**********@yahoo.com> wrote
in comp.lang.c++:
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?

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: ja*********@free.fr
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! ]

Oct 2 '05 #8

John wrote:
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! ]

Oct 3 '05 #9
benben wrote:
"John" <we**********@yahoo.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
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?

[...] 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! ]

Oct 3 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Vadim Biktashev | last post by:
Hello all I would like to give a certain name to a certain global variable. Unfortunately, this name is already used in math.h for a mathematical function. Worse, I do need to use maths library...
1
by: S.Tobias | last post by:
typedef int myint; struct s { myint myint; /* 1 */ } s; int main() { myint myint; /* 2 */
3
by: CsaaGuy | last post by:
Hi, i created a class that i have showing up at design time and i have to save some of the properties to the viewstate at runtime. It all works fine, however the issue is if i have more that one...
2
by: Whywhat | last post by:
Hi! I have a name conflict between my class and windows.h header. The problem is because of windows.h contains GetMessage macro and my class a method with the same name. Thus the macro replaces...
0
by: Mathieu Cartoixa | last post by:
Hi, I have a simple 2-tiers (client+database) application with simple Domain Model objects The Data Access Layer is abstracted via Data Mappers which use Data Transfer Objects to communicate...
5
by: Yas | last post by:
Hello, I have the following table with 4 columns.... firstname, lastname1, lastname2, EMAIL Table has user names and email, I would like to generate a 5th column called DisplayName. The email...
14
lotus18
by: lotus18 | last post by:
Hello all I have these records on my Day Table for my complete database table please click here 1. M 2. T 3. W 4. TH 5. F 6. S
35
by: erik gartz | last post by:
Hi. I'd like to be able to write a loop such as: for i in range(10): pass but without the i variable. The reason for this is I'm using pylint and it complains about the unused variable i. I can...
9
by: Meendar | last post by:
Hi, Below is my code snippet having only one form, <form> <input type ="radio" name="action" value="xyz" checked>xyz <input type ="radio" name="action" value="zyx">zyx <input type ="radio"...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.