Hi
I have this peculiar situation. I have a library of utility classes,
which I use to compile a binary. I want to reimplement a method in
class. The class is only a collection of static methods.
So I copy the source and header files to another place, change the
include path so this location will precede the location of the headers
of the library, change the method (details after) and compile.
Everything works, except when linking. The linker complains about some
static methods in the class, but not all of them. Is there a general
reason for that?
The chnage in the method is to add another parameter, with a default
value.
Btw, just copying the files, with no changes compiles fine.
Thanx,
Ittay 7 1910
On 30 Jun 2004 23:37:22 -0700, Ittay Dror <no*****@mailinator.com> wrote: Hi
I have this peculiar situation. I have a library of utility classes, which I use to compile a binary. I want to reimplement a method in class. The class is only a collection of static methods.
So I copy the source and header files to another place, change the include path so this location will precede the location of the headers of the library, change the method (details after) and compile.
Everything works, except when linking. The linker complains about some static methods in the class, but not all of them. Is there a general reason for that?
The chnage in the method is to add another parameter, with a default value.
Btw, just copying the files, with no changes compiles fine.
Thanx, Ittay
Sounds to me like you are trying to use your modified class to hide the
original class by making sure that the modified classes are included and
linked first, is that correct? If so then you are breaking the one
definition rule (ODR) which says that if multiple copies of a class are
compiled then those copies must be identical, otherwise you have undefined
behaviour.
john
On Thu, 01 Jul 2004 07:49:51 +0100, John Harrison
<jo*************@hotmail.com> wrote: On 30 Jun 2004 23:37:22 -0700, Ittay Dror <no*****@mailinator.com> wrote:
Hi
I have this peculiar situation. I have a library of utility classes, which I use to compile a binary. I want to reimplement a method in class. The class is only a collection of static methods.
So I copy the source and header files to another place, change the include path so this location will precede the location of the headers of the library, change the method (details after) and compile.
Everything works, except when linking. The linker complains about some static methods in the class, but not all of them. Is there a general reason for that?
The chnage in the method is to add another parameter, with a default value.
Btw, just copying the files, with no changes compiles fine.
Thanx, Ittay
Sounds to me like you are trying to use your modified class to hide the original class by making sure that the modified classes are included and linked first, is that correct? If so then you are breaking the one definition rule (ODR)
I should say probably breaking the ODR. The issue is whether parts of your
program are compiling the old definitions and parts the new definitions.
john
"Ittay Dror" <no*****@mailinator.com> wrote in message
news:10**************************@posting.google.c om... Hi
I have this peculiar situation. I have a library of utility classes, which I use to compile a binary. I want to reimplement a method in class. The class is only a collection of static methods.
So I copy the source and header files to another place, change the include path so this location will precede the location of the headers of the library, change the method (details after) and compile.
Everything works, except when linking. The linker complains about some static methods in the class, but not all of them. Is there a general reason for that?
The chnage in the method is to add another parameter, with a default value.
Btw, just copying the files, with no changes compiles fine.
Thanx, Ittay
How about the order of linking?
How are you using the modified implementation? Are you adding the modified
implementation to your compilations (or project)?
For example you could do it like this while linking (I am giving a VC
example)
cl.exe modified.cpp -> to give modified.obj
link.exe xxx, yyy, modified.obj....
If you still link to the old library (maybe a .lib file), the problem would
arise because of the difference in your header and the old lib.
You should not be still linking to the old library - you should include the
modified source file in your project rather.
Senapathy
"John Harrison" <jo*************@hotmail.com> wrote in message news:<opsaf5ruwe212331@andronicus>... On Thu, 01 Jul 2004 07:49:51 +0100, John Harrison <jo*************@hotmail.com> wrote:
On 30 Jun 2004 23:37:22 -0700, Ittay Dror <no*****@mailinator.com> wrote:
Hi
I have this peculiar situation. I have a library of utility classes, which I use to compile a binary. I want to reimplement a method in class. The class is only a collection of static methods.
So I copy the source and header files to another place, change the include path so this location will precede the location of the headers of the library, change the method (details after) and compile.
Everything works, except when linking. The linker complains about some static methods in the class, but not all of them. Is there a general reason for that?
The chnage in the method is to add another parameter, with a default value.
Btw, just copying the files, with no changes compiles fine.
Thanx, Ittay
Sounds to me like you are trying to use your modified class to hide the original class by making sure that the modified classes are included and linked first, is that correct? If so then you are breaking the one definition rule (ODR)
I should say probably breaking the ODR. The issue is whether parts of your program are compiling the old definitions and parts the new definitions.
john
classes from within the library use the old definition, classes from
the new one use the new definition. but why does it matter? to the
compiler/linker there are two distinct methods, e.g., static void
A::foo(int i) in the library, and static void A::foo(int i, int j) in
my code. After mangling, they should be distinct symbols, afaik.
ittay
On 1 Jul 2004 04:23:43 -0700, no*****@mailinator.com (Ittay Dror)
wrote: classes from within the library use the old definition, classes from the new one use the new definition. but why does it matter? to the compiler/linker there are two distinct methods, e.g., static void A::foo(int i) in the library, and static void A::foo(int i, int j) in my code. After mangling, they should be distinct symbols, afaik.
From what you said earlier, some methods have two different
definitions, one in the library and one in the separate source file.
The linker doesn't know which one is the correct one, hence the
multiple definition error. If you used a DLL rather than a static
library (under Windows), the problem would probably go away, or become
more subtle.
Having two different definitions of a class in one program is a
frankly terrible idea, since even if you get it working, it will be
fragile if you try it on a different compiler, or even with different
compiler options.
What are you trying to do? Why can't you just derive a new class from
the old one, adding the new definitions you want, and even hiding the
old ones if appropriate.
Tom
--
C++ FAQ: http://www.parashift.com/c++-faq-lite/
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
> > john classes from within the library use the old definition, classes from the new one use the new definition. but why does it matter? to the compiler/linker there are two distinct methods, e.g., static void A::foo(int i) in the library, and static void A::foo(int i, int j) in my code. After mangling, they should be distinct symbols, afaik.
The only people who can answer that are the developers of your particular
compiler/linker. The C++ standard simply says it is undefined behaviour.
That's the only answer that is applicable on this newsgroup. For an answer
to why it happens on your particular platform you should ask on a group that
deals with your particular platform.
john
On 4 Jul 2004 01:13:51 -0700, no*****@mailinator.com (Ittay Dror)
wrote: tom_usenet <to********@hotmail.com> wrote in message news:<m5********************************@4ax.com>. .. [snip...] Having two different definitions of a class in one program is a frankly terrible idea, since even if you get it working, it will be fragile if you try it on a different compiler, or even with different compiler options.
What are you trying to do? Why can't you just derive a new class from the old one, adding the new definitions you want, and even hiding the old ones if appropriate.
the class is just a collection of static methods. deriving from it won't help me here (i can do it, but i am just extending an existing method's functionality, i don't want some places in my code calling A::foo and others A2::foo)
How about using namespaces? Put the modified version of A in a
different namespace? Then you can add a using declaration for the one
you want to use in that source file. Fighting against the language
rules is not really worth it. A non-inline function shall have one and
only one definition.
Tom
--
C++ FAQ: http://www.parashift.com/c++-faq-lite/
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: prettysmurfed |
last post by:
Hi all
I have this, probably stupid question, how to avoid multiple
definitions when a header file is included more than once.
I thought, when you wrote the header-file and used the...
|
by: Martin Magnusson |
last post by:
I have a problem with multiple definitions that I can't quite straighten
out.
I have a templated class defined inside a namespace, and I want to
create a function in that namespace that works on...
|
by: Charles L |
last post by:
Can someone explain to me what the following means?
"C permits multiple definitions of a variable in any given namespace,
provided the definitions are the same and it generates only a single...
|
by: Daniel |
last post by:
I use an Access database to basically take data exports, import them,
manipulate the data, and then turn them into exportable reports. I do
this using numerous macros, and queries to get the data...
|
by: JackyMove |
last post by:
Dear all,
I have encount the following problem. I have compiled a library
"lib.lib" successfully using a simulator compatable to VC++ on Windows
platform. Then I try to build an executatble in...
|
by: Carramba |
last post by:
hi!
I have program with several funktion witch are in separete files,
I have one include file were I have definet some variables and initiated
'const double fVar=0.874532;'
this files is includet...
|
by: yossi.kreinin |
last post by:
Hi!
When are multiple definitions of global variables with the same name
considered legal in C, and how is it different from C++? It appears
that in terms of assembly language, some C...
|
by: javan |
last post by:
Hello,
I am new to C++, coming from a background in Java and procedural languages. I am currently translating some code from Java to C++ as an exercise and have run into the following problem:
...
|
by: junyang |
last post by:
Hi all,
I have one DTD fragment, base.dtd, that contains a bunch of useful
element definitions (say an element named "base"), and two DTD
fragments, a.dtd and b.dtd, that each build on base.dtd...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
| |