473,320 Members | 2,029 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,320 software developers and data experts.

templated functions and multiple definitions in obj files

I have a templated function called splitAndSegment (templated on the
datatype). It's declared in a header file. I then include that header
file in two separate cpp files and link them separately. Both files
use the function, and both use the same instantiation of the function
(datatype int). Thus they both instantiate the function in their
separate obj files. I declare the function inline to prevent linking
problems, but I get linking problems anyway.

template<typename T>
inline
void splitAndSegment(T * in, unsigned int * temp1, T * temp2,
Flag * ihflags, Flag * ihtflags,
const Flag * cmpflags)
{ definition here ... }

Linking errors:

Linking...
test_app.obj : error LNK2005:
__ZZ15splitAndSegmentIiEvPT_PjS1_PiS3_PKiEs_0 already defined in
sort_app.obj
test_app.obj : error LNK2005:
__ZZ15splitAndSegmentIiEvPT_PjS1_PiS3_PKiEs already defined in
sort_app.obj
test_app.obj : warning LNK4006:
__ZZ15splitAndSegmentIiEvPT_PjS1_PiS3_PKiEs_0 already defined in
sort_app.obj; second definition ignored
test_app.obj : warning LNK4006:
__ZZ15splitAndSegmentIiEvPT_PjS1_PiS3_PKiEs already defined in
sort_app.obj; second definition ignored

I'm totally puzzled and would appreciate any help on figuring out why
this occurs. It's on MS Dev Studio v. 7.10.3077 (I believe it's VS
2003).

JDO

Feb 3 '07 #1
3 2412
jo********@yahoo.com wrote:
I have a templated function called splitAndSegment (templated on the
datatype). It's declared in a header file. I then include that header
file in two separate cpp files and link them separately. Both files
use the function, and both use the same instantiation of the function
(datatype int). Thus they both instantiate the function in their
separate obj files.
....
I'm totally puzzled and would appreciate any help on figuring out why
this occurs. It's on MS Dev Studio v. 7.10.3077 (I believe it's VS
2003).
This would be a bug in your linker. The linker is supposed to eliminate
duplicate instantiations.

One ugly work around is to place the function in an anonymous namespace.
There are probably others.
Feb 3 '07 #2
On Feb 2, 5:07 pm, Gianni Mariani <gi3nos...@mariani.wswrote:
This would be a bug in your linker. The linker is supposed to eliminate
duplicate instantiations.

One ugly work around is to place the function in an anonymous namespace.
There are probably others.
I'm a little unclear why this error might occur then.

http://msdn2.microsoft.com/en-us/library/72zdcz6f.aspx

Those seem like pretty specialized cases. I'm baffled, since my case
seems much more general.

JDO

Feb 3 '07 #3
jo********@yahoo.com wrote:
On Feb 2, 5:07 pm, Gianni Mariani <gi3nos...@mariani.wswrote:
>>This would be a bug in your linker. The linker is supposed to eliminate
duplicate instantiations.

One ugly work around is to place the function in an anonymous namespace.
There are probably others.


I'm a little unclear why this error might occur then.

http://msdn2.microsoft.com/en-us/library/72zdcz6f.aspx

Those seem like pretty specialized cases. I'm baffled, since my case
seems much more general.
That one has to do with the strange way MS libraries of different kinds
are linked. It has little to do with the issue in the OP.
Feb 3 '07 #4

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

Similar topics

47
by: Richard Hayden | last post by:
Hi, I have the following code: /******************************** file1.c #include <iostream> extern void dummy(); inline int testfunc() {
21
by: Rubén Campos | last post by:
I haven't found any previous message related to what I'm going to ask here, but accept my anticipated excuses if I'm wrong. I want to ask about the real usefulness of the 'inline' keyword. I've...
6
by: Charlie | last post by:
Ok, I have three files: calc.cpp, calc.h, and ui.cpp. I would like to call a function that is located in ui.cpp from main() in calc.cpp. Both files have calc.h included, but when I tried to...
7
by: Srini | last post by:
Hello, Rules for inline functions say that they have to be defined in the same compilation unit as their declarations. For class member functions this means that the inline member functions must...
5
by: moumou | last post by:
Hello world ! This may be a naive question, so I apologize in advance ! I'm wonderting if it is possible to find a program that takes a C source code file and split it into multiple files, one...
14
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...
15
by: kwikius | last post by:
Hi all, I have been searching through the list of papers at: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/ I seem to remember a proposal regarding templated namespaces e.g: template...
4
by: sofeng | last post by:
The following link shows a chart I created about passing structures among functions. Would you review it and tell me if it requires any corrections? ...
6
by: mathieu | last post by:
Hi there, I am currently struggling with a compiler error on a templated code. The error is complete non-sense. I think the issue here is that I am including files in a loop. To handle templates...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
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: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
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 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.