Solved

URGENT:  Header Files / Linking Problem

Posted on 2003-10-30
8
285 Views
Last Modified: 2012-05-04
I have a COM dll I am writing with 4 different interfaces / classes.  I have some classes, structs and globals defined in a .H file (its all in the .H file, there is no cpp file)

When I include the .H file in one of the headers for the 4 classes, I have no problem.

When I include the .H file in two of the headers for the 4 classes, I get all sorts of

SYMBOLICFucntionName already definien in Object2.obj, where Object2 is the second object I added the #include directive to.  There are no errors for Object1, the original object that #included my header with objects and enums.  

Am I not allowed to do this?  If not, how do I restrucutre the linking/files so that I can do something like this?  
If so, why is this not working?
0
Comment
Question by:jjacksn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 86

Assisted Solution

by:jkr
jkr earned 100 total points
ID: 9652050
Do you have "multiple inclusion guards", e.g.

//MyHeader.h:
#ifndef __MyHeader_h
#define __MyHeader_h

// rest of the header file goes here...

#endif
?
0
 
LVL 5

Author Comment

by:jjacksn
ID: 9652102
I added them, it didn' t fix the problem.
0
 
LVL 5

Author Comment

by:jjacksn
ID: 9652120
Also, when I don't have the header in there, I can't access the objects in the class that is causing the problems, so I don't think I have multiple inclusion problems.  I think it has something to do with the fact that they are all in the COM class perhaps? the .h file is creating global objects.  just a thought.  
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Expert Comment

by:jkr
ID: 9652157
This _usually_ fixes the problem you described. Are you sure the #ifndef/#endif part encloses *all* of your file? Could you post the code?
0
 
LVL 6

Expert Comment

by:GloomyFriar
ID: 9652320
>its all in the .H file, there is no cpp file
You have to split them on cpp and h.
There is no good way to solve the problem, if you have a code in your H file not only headers.
0
 
LVL 6

Expert Comment

by:GloomyFriar
ID: 9652350
Other way:

---myh.h---
void SomeFunc(void);

#ifndef CODE_ALREADY_DEFINED
void SomeFunc(void)
{
}
#endif
--------------

---file1.cpp---
#include "myh.h"
----------------

---file2.cpp---
#define CODE_ALREADY_DEFINED
#include "myh.h"
----------------

---file3.cpp---
#define CODE_ALREADY_DEFINED
#include "myh.h"
----------------

...
0
 
LVL 6

Assisted Solution

by:GloomyFriar
GloomyFriar earned 150 total points
ID: 9652375
One correction:

---myh.h---
#ifndef ___MYH_H_
#define ___MYH_H_

/* Put all declarations here */
void SomeFunc(void);

#ifndef CODE_ALREADY_DEFINED
/* Put all code in the such sections */
void SomeFunc(void)
{
}
#endif

#endif
--------------
0
 
LVL 9

Accepted Solution

by:
_ys_ earned 250 total points
ID: 9653221
>> its all in the .H file, there is no cpp file
This will lead to multiple definitions of the objects within, guaranteed - unless of course you only have a single compilation unit (cpp file), which would be unusual.

Create a .cpp file, and move _all_ of the definitions to there. Your .h file, if neessary, can extern all those items removed.

GloomyFriar gave a good example, a function. If your current .h file has this

void SomeFunc(void)
{
}

then that would be moved to the .cpp, and your .h file would retain

extern void SomeFunc(void);

If you post the contents of your .h file, I'm sure somebody could aid in splitting them up with you.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
C++ get user from AD  (VS6) 7 114
computer science syllabus 3 118
C++ mouse_event mouse look 7 136
How to convert Structure to vector of byte and vice versa 5 42
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question