473,722 Members | 2,459 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with multiple definition

Hello all.
I've got a problem of multiple definition in a program that at first
glance looks correct (I won't type the whole code, just the relevant one
and as examples since seems is a linkage problem):

main.cpp
========
using namespace std;
....

#include "myHeader.h " // This is the header that causes the problem

....

int main()
{
...

Function_in_myH eader();

...
}

myHeader.h
==========
#ifndef MYHEADER_H
#define MYHEADER_H

....

void Function_in_myH eader(void);

#endif

myHeader.cpp
============
....

#include "myHeader.h " // I suspect the problem is here

....

void Function_in_myH eader(void)
{
- do something -
}

As I said, this structure arises a multiple definition error of
Function_in_myH eader (also of other identifiers declared in myHeader.h)
The problem is that I need to include myHeader.h in myHeader.cpp because
when I remove it the compiler throws errors of undeclared identifiers.
I tried also compile the program embedding the line within #ifndef
#define #endif but the result is the same as if I remove the line: not
declared identifiers/functions errors arise.

I have no clue about what is wrong.
Btw, I use gcc with CodeBlocks frontend and the program is compiled as C++

Thank you in advanced.
Feb 1 '08 #1
3 3058
As I said, this structure arises a multiple definition error of
Function_in_myH eader (also of other identifiers declared in myHeader.h)
The problem is that I need to include myHeader.h in myHeader.cpp because
when I remove it the compiler throws errors of undeclared identifiers.
I tried also compile the program embedding the line within #ifndef
#define #endif but the result is the same as if I remove the line: not
declared identifiers/functions errors arise.
Are you compiling myHeader.cpp into myHeader.o then linking that with
main.cpp?

If you have implemented (i.e. provided a function body for)
function_in_myH eader IN the header itself then the function will be
defined in myHeader.o and you will get a multiple definition error
when you then link that with main.cpp
Any help? If not can you post the contents of myHeader.h and the
makefile/commands you use to compile it.

--rob
Feb 1 '08 #2
On Feb 1, 11:34*am, Antonio Rivas <cha...@telefon ica.netwrote:
Hello all.

main.cpp
========
using namespace std;
...
#include "myHeader.h " // This is the header that causes the problem
...
An unrelated point - you want to get into the habit
of putting your "using namespace ..."s *after* your
#includes; you may save yourself hours of head-scratching
one day.

Feb 1 '08 #3
tragomaskhalos escribió:
On Feb 1, 11:34 am, Antonio Rivas <cha...@telefon ica.netwrote:
>Hello all.

main.cpp
========
using namespace std;
...
#include "myHeader.h " // This is the header that causes the problem
...

An unrelated point - you want to get into the habit
of putting your "using namespace ..."s *after* your
#includes; you may save yourself hours of head-scratching
one day.
I know, sorry, in the source code is correctly placed after not before :)
But thanx for the reminder :)
Feb 1 '08 #4

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

Similar topics

11
17822
by: Georg Teichtmeister | last post by:
Hello! We are developing a math - library for realtime applications and want to use some given mathlibraries as base(ipp, MTL, .. ). Our library is a wrapper for those and you should be able to select the underlying library by template parameter. Therefore we split up our library in two namespaces: The first one defines namespace-global functions which call the baselibrary functions. These are templatefunctions which some
2
3284
by: Christian Christmann | last post by:
Hi, I'm using "flex" which is creating a file called lex.yy.c and this C file is added to a library. In another directory I have to use flex for another file and also add the second lex.yy.c to another library. Hence, I need to include both libraries and while linking I get an e.g. "multiple definition of `yyleng'" since yyleng is created in both lexx.yy.c. I can't change the variable name yyleng since it's
9
3480
by: ludocluba | last post by:
Hello, here is my problem: I have 3 files: main.c toto.c toto.h: ----------------------------------------------------------- toto.h: #ifndef _toto_h #define _toto_h int var; void test(void); #endif -----------------------------------------------------------
1
3363
by: abh1508 | last post by:
Following a release of code the following problem occurs on certain asp ..net pages. This is not a problem on other testing/demo environments. IIS seems to be creating certain files twice in the temporary internet files directory. Any advice or suggestions appreciated. Server Error in '/ContactCentre/Global' Application. -------------------------------------------------------------------------------- Compilation Error
5
5692
by: Karl | last post by:
Hey everyone! So I'm writing my own String class to wrap std::string and implement an API as close to identical as possible to the Java API. It's pretty small so far: #include <string> class String {
3
2145
by: Jens Müller | last post by:
I have a file here with several enums: #ifndef PLANARSEP_OPTIMIZE_H #define PLANARSEP_OPTIMIZE_H enum fund_cycle_behavior_t {PASS_MODE_FIRST, PASS_MODE_BEST, PASS_MODE_ALL};
5
2271
by: PaperPilot | last post by:
I have defined a vector and its iterator as such: typedef std::vector< WindsTableElement > WindTable; WindTable wt_; WindTable::iterator windIterator_; I get no errors during compile, but during linking I get: What am I doing wrong?
10
1702
by: michael | last post by:
Hi All, I have the following: ------------ file constants.h--------- #ifndef constants_ #define constants_ const int FOO = 1; const int BAR = 2;
7
2996
by: bcpkh | last post by:
Hello All Received a header file from a supplier that defines an interface to implement but it's giving me a problem, I reproduce the general structure of the header file below; #ifndef XYZ_H various #define(s)
0
8867
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8740
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9386
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9158
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8059
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5996
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4503
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3208
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2606
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.