Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unable to solve '...multiply-defined' error

Status
Not open for further replies.

DCCoolBreeze

Programmer
Jul 25, 2001
208
0
0
US
I am unable build a program because I am getting a `DwString::~DwString()` multiply-defined error. I am working in DYNIX/ptx v4.5.1 using c++ v5.2.5.

First I build 3 libraries...

$(DEV_DIR)/libmimepp_core.a : $(DEV_DIR) $(DEV_CORE_OBJS)
$(CXX) -xar -o $(DEV_DIR)/libmimepp_core.a $(DEV_CORE_OBJS)

$(DEV_DIR)/libmimepp_util.a : $(DEV_DIR) $(DEV_UTIL_OBJS)
$(CXX) -xar -o $(DEV_DIR)/libmimepp_util.a $(DEV_UTIL_OBJS)

$(DEV_DIR)/libmimepp_net.a : $(DEV_DIR) $(DEV_NET_OBJS)
$(CXX) -xar -o $(DEV_DIR)/libmimepp_net.a $(DEV_NET_OBJS)

I get a "relink" notification but the libraries do build so
Now I try to build the application...

.../mimepp/examples/pop-> make pop_ex
c++ -c -g -I../../src pop_ex.cpp
c++ -g -o pop_ex pop_ex.o -I../../src -L../../dev
-lmimepp_net -lmimepp_core
ld: ../../dev/libmimepp_net.a(protocol.o): fatal error: symbol`DwString::~DwString()` multiply-defined, also in file pop_ex.o
c++: Fatal Error: Link failed

All header files contain #define "header symbol" statements.

Can anyone help?
 
It sounds like a possible circular include problem. I ran into this a while back. What was happening was A included B which Included C which included A (or something like that)

Our fix (though i am not sure if it was a good one) was to use forward declarations for our classes in the header files and put the includes in the .cpp files. If a class was not mentioned in the .h file then we used no forward declaration.

See if this helps any.

Matt


 
1. .h files should have structure like

#if !defiled(__sometnihg_is_up_to_you_what)
#define __sometnihg_is_up_to_you_what
....declarations here
#endif

such structure of .h files avoid multimpe declaration. You can include many times the same .h in the same place without problems.

2. Variables declarations should be put in .c/.C/.cc/.cpp files. for example
int x;//declaration and definition
but in .h file
extern int x;//forward declaration without definition
is not a problem you to put many times
extern int x;
extern int x;
extern int x;//compiller will not complain
Also you can put it (forward declaration)in source c/C/cc/cpp file you're using this variable. Ion Filipski
1c.bmp


filipski@excite.com
 
Thanks for the information. I will review all of the files to see if they require these changes....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top