473,698 Members | 2,603 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

using #ifndef

I have a program where both my main.c and program.c files use the program.h
file. So I #include "program.h" in both the .c files. The program.h file
has
#ifndef PROGRAM_H
#define PROGRAM_H
....
#endif

Yet when I build my program, the DJGPP compiler tells me there are multiple
definitions of each of my functions.

Any ideas as to what I doing wrong here?

Thanks!

John

Nov 14 '05
25 4898
"E. Robert Tisdale" wrote:

Alan Balmer wrote:
John Hanley wrote:

I had to look up the message ID to see who you were responding to,
since you didn't provide attributions. As it turns out,
I couldn't tell by the threading
because I have ERT permanently killfiled.


And I'm grateful for that.
Ignore him. Most everyone else does.


Do you intend to help John Hanley with the problem that he describes?


What part of killfiled does Trollsdale not understand?

Then again, there are so many things he fails to understand.


Brian Rodenborn
Nov 14 '05 #21
On Fri, 27 Aug 2004 16:11:13 GMT, Default User
<fi********@boe ing.com.invalid > wrote:
"E. Robert Tisdale" wrote:

Alan Balmer wrote:
> John Hanley wrote:
>
> I had to look up the message ID to see who you were responding to,
> since you didn't provide attributions. As it turns out,
> I couldn't tell by the threading
> because I have ERT permanently killfiled.


And I'm grateful for that.
> Ignore him. Most everyone else does.


Do you intend to help John Hanley with the problem that he describes?


What part of killfiled does Trollsdale not understand?

Then again, there are so many things he fails to understand.

The funny thing is that I *did* help John Hanley with the problem he
describes. In the post I replied to, his problem was that our resident
troll has been unnecessarily rude to him. I suggested a solution to
that problem.

--
Al Balmer
Balmer Consulting
re************* ***********@att .net
Nov 14 '05 #22
On Fri, 27 Aug 2004 10:23:37 -0600, "John Hanley"
<jd******@telus planet.net> wrote:
Ok, it seems my code wasn't what was buggy. I am using the RHIDE ide for
djgpp. When I built it at the command line just now it didn't give me
errors. I think what I did was when I created my "project" in RHIDE, I
added my files including my .h file. I just removed my .h file from the
project and it didn't give me any errors in RHIDE.

Sorry for taking up all this time on such a small oversight. I really do
appreciate the replies and all the help.

Not a problem. Such posts are often valuable for the side effects :-)

--
Al Balmer
Balmer Consulting
re************* ***********@att .net
Nov 14 '05 #23
On Fri, 27 Aug 2004 08:55:06 -0600
"John Hanley" <jd******@telus planet.net> wrote:

"Keith Thompson" <ks***@mib.or g> wrote in message
news:ln******** ****@nuthaus.mi b.org...
<snip>
I suspect the problem is in some detail that you're not telling us,
perhaps because you've assumed it's not significant. That's
understandable; if you were knowledgeable enough to know exactly
what's significant and what isn't, you probably wouldn't have to
come to us for help. Since you are coming to us for help, you
really should give us the information we're asking for. We need a
verbatim cut-and-paste *brief* example of the C code that's causing
the problem. Without that, we can't help you.


Sounds good. I'll post that at the bottom of this reply.


<snip>
Ok, here's my header file r_climat.h

struct data_record
{
...
};
<snip>
struct parameter_list
{
...
}parameters;


This could be your problem (unless my brain is temporarily
non-functional, which is possible after the week I've had). I assume you
mean either:

typedef struct parameter_list
{
...
}parameters;

or:

struct parameter_list
{
...
};

You could have other similar problems in the bits you have not included.
and here's r_climat.c


#include "r_climat.h "

#define HLY 0
#define DLY 1
#define MLY 2
#define FIF 3

/* initialize head and tail of data_list to NULL */
void init(struct data_list * l)
{
l->head=NULL;
l->tail=NULL;
}

and the rest of my functions that would take another 800 lines or so.

I only define them in my r_climat.c (I know I don't define any in
main.c) and I only prototype them
in r_climat.h. They all compile just fine with no errors or warnings.
It
is during linking that I get this
"multiple definitions" error.

Let me know if there is anything else specific you would like.

Thanks again for all your help. I really do appreciate all of it.


What we want is something that compiles and shows the problem.

Delete functions one at a time until either you have something short
that compiles and shows the problem (i.e. fails linking with multiple
definitions).

You may even find that in deleting bits you stumble across the cause of
the problem yourself.
--
Flash Gordon
Sometimes I think shooting would be far too good for some people.
Although my email address says spam, it is real and I read it.
Nov 14 '05 #24
"John Hanley" <jd******@telus planet.net> writes:
"Keith Thompson" <ks***@mib.or g> wrote in message
news:ln******** ****@nuthaus.mi b.org... [...]
This is Usenet, not email. The difference is significant; though your
remarks here might be aimed at one person, there are many more
listening in.


True. I actually was replying to an email. Mr. Tisdale had replied
to my post over email and cc'd the newsgroup. I did a reply all and
replied to both. I should've realized it probably shouldn't have
gone to the newsgroup as well (being more of a personal reply). My
apologies for breaking any Usenet etiquette.


In my opinion, that was ERT's fault for sending his response both by
e-mail and to the newsgroup. It rarely makes sense to do that. If I
see an e-mail response to something I've posted on Usenet, I'm likely
to assume that it was only a private response, and reply to it
privately; later, when I check the newsgroup, I find that I wasted my
time when I should have just posted publicly. (Actually, I'm more
likely to check first, since I've fallen into this trap a couple of
times.) If a response is sent both by e-mail and to the newsgroup, it
should be clearly labeled at the top.
You can continue describing what you're doing, and we can continue
telling you we don't know what the problem is. Or you can show us
what you're doing, and we can probably help. The choice is yours (but
one of the choices would be a collosal waste of time and, well, rude.)


Ok, here's my header file r_climat.h

struct data_record
{
...
};


I don't believe your header file has a "..." in the definition of
struct data_record. More on that below.

[snip]
As for my "multiple declaration" problem, here's the snippet of my .c files: [...] int main(int argv, char * argc[])
{
main program here
}
and here's r_climat.c
#include "r_climat.h "

[...] and the rest of my functions that would take another 800 lines or so.


I'm glad to see from another response you posted in this thread that
you were able to figure out the problem (something about another file
that your IDE picked up when you didn't want it to). But I'm going to
offer some constructive criticism anyway. Keep in mind this is
absolutely meant to be *constructive* criticism; it's also for the
benefit of other readers.

After going back and forth several times, you never actually gave us
what we asked for. First, you gave us a brief summary of what your
source code looked like. Then, you gave us snippets of your source
code (see above), but nothing that anyone else could actually compile.

What you should have done was something like this:

Copy all your source files to a separate directory (or the equivalent
for your system) and start ripping things out. If you're getting an
error message that refers to a particular function, delete everything
other than that one function. Delete everything you can from the body
of the function; narrow it down to something like:

some_type my_func(int foo, char *bar)
{
some_type dummy;
return dummy;
}

and narrow your main program down to:

#include "my_header. h"
int main(void)
{
some_type result;
result = my_func(0, NULL);
return 0;
}

At each step, from the complete source code down to a minimal version
of it, recompile and confirm that you're still getting the same error
message. With luck, you'll be able to narrow the problem down to a
few dozen lines of code, small enough to post here. If you're really
lucky, you'll figure out while you're doing this what the problem is
(in your case, you probably would have figured that out the first time
you tried to compile in a new directory). The important point is that
the rest of us can then try compiling your code ourselves. If the
code you post has things like "..." and "main program here", we can't
do that.

When we ask for the exact code that's causing the problem, we mean
exactly that -- the *exact* code, not a summary, not a snippet. If
the code causing the problem is too big to post, you can almost
certainly trim it. If you're looking at problem that shows up during
compilation or linking, the trimmed version of the program doesn't
even have to do anything useful, as long as it produces the same error
message.

And speaking of error messages, you should also post the exact error
message. Telling us that the compiler "tells me there are multiple
definitions of each of my functions" may not be sufficient;
cut-and-paste the actual error message. If you haven't figured out
the problem, don't assume that your summary of the error message won't
leave out some critical detail that you haven't recognized.

Finally, let me recommend a web page that probably covers everything
I've written here better than I have: "How To Ask Questions The Smart
Way" by Eric Raymond and Rick Moen,
<http://www.catb.org/~esr/faqs/smart-questions.html> .

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #25
John Hanley wrote:
I have a program where both my main.c and program.c files use the program.h
file. So I #include "program.h" in both the .c files. The program.h file
has
#ifndef PROGRAM_H
#define PROGRAM_H
...
#endif

Yet when I build my program, the DJGPP compiler tells me there are multiple
definitions of each of my functions.


Function definitions ought to go in C files.
And function declarations aka prototypes ought to go in a h file.

If you can make sure this separation does exist in your project,
then your compiler should not have any problem.
Problems comes into picture the moment you bring in a function
definition in a header file.

--
Karthik
Nov 14 '05 #26

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

Similar topics

5
1878
by: John Gabriele | last post by:
I'm hoping someone can please help me remember the C++ rule: When you're writing a header file for a class (say, some_namespace::Bar), and that class makes use of another class (some_namespace::Foo), -------------------------------- snip -------------------------------- #ifndef GUARD_Foo_HPP #define GUARD_Foo_HPP namespace some_namespace {
3
3203
by: Michael Sgier | last post by:
Hello I get the error below. But why and what does ifndef? Well what is ifndef? Many thanks and regards Michael error: syntax error before `(' token #ifndef MD2SwapInt static __inline__ Uint32 MD2SwapInt(Uint32 D) {
1
2757
by: Xiangliang Meng | last post by:
Hi, all. Recently, I find there is a way in our project to maintain a global set in many files by using preprocessing directives. I'm wondering if we could find a better method for this. Many colors are referred in different subsystems in our projects. They are defined as enumeration constants and a single color must be the same value all across our projects.
9
28679
by: Qiao Jian | last post by:
I am new to c. Today I just read an h file within which there is statements: #ifndef _RANDOM_H #define _RANDOM_H So what is the meaning or purpose of this statement? When should I use such statement in my own program? Thank you so much!
2
1510
by: praveenkojha | last post by:
Hi, I am novice in C++ and am more of a C# guy. I have a third party C++ code which I want to create and use as a managed assembly. I have created a .NET win32 application and have copied this C++ code here and made changes according to my needs. However I am always getting this linker error when compiling. I looked a lot n the web and followed all instructions so far of adding msvcrt.lib, glu32.lib, opengl32.lib to the project...
4
1121
by: Jamiil | last post by:
I have a class which only purpose is to provide services to a variety of classes in other files. The 'manipulator' class is aware of the other classes only because the header files have been include in its header file. However, there are times when some of the other classes are not and will not be dealt with, thus the need to include the header files does not arrive. To handle this, I have used compiler preprocessors to prevent the...
25
2142
by: David Sanders | last post by:
Hi, As part of a simulation program, I have several different model classes, ModelAA, ModelBB, etc., which are all derived from the class BasicModel by inheritance. model to use, for example if the parameter model_name is "aa", then choose ModelAA. Currently I do this as follows:
14
2197
by: aaragon | last post by:
Hi everyone, I've been writing some code and so far I have all the code written in the .h files in order to avoid the linker errors. I'm using templates. I wanted to move the implementations to the .cpp files. After some reading, I found that the only way to do this is to add the actual template instantiations in the .cpp file. But, how do you do that if you're not working with built-in types? For example, a template class might be,
2
2149
by: sydneytroz | last post by:
I'm getting a rather odd set of error messages when I try compiling the below code. I'm using the Dev-C++ IDE on WinXP, and am using a small driver program (unit-dev.cpp) to test the classes (it includes both the file listed below) The messages are: In file included from unit-dev.cpp:27: D:/Documents and Settings/Zachary/My Documents/School/G11/Computer Science/VirtOS/src/ipc/messagehandler.h:27: error: using-declaration for non-member at...
0
8609
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
8871
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7738
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...
1
6528
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5861
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
4622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
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
2335
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.