using #ifndef

F

Flash Gordon

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

Ok, here's my header file r_climat.h

struct data_record
{
...
};

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.
#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.
 
J

John Hanley

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.

Thanks so much!

John
 
A

Alan Balmer

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.
 
A

Alan Balmer

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 :)
 
K

Keith Thompson

John Hanley said:
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.
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>.
 
K

Karthiik Kumar

John said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,798
Messages
2,569,651
Members
45,382
Latest member
tallzebra

Latest Threads

Top