Bugs in my code, help!!

J

Jamiil

This is not a question where the source code is important, it is not
important at all. So don't expect to find answers to my questions in
the code; the answers will be in how the class interacts with the rest
of the program and/or how GCC can help me resolve my problem.

Having said that, I have a class called 'Person', and a class
called 'io_base', the purpose of 'io_base' is to implement file
input and output in a uniform manner for all my classes. All the user
of this class has to do is ask 'io_base' to open a file and then,
via the use of inserters and extractors, input or output data to and
from the file, as simple as that. The class takes care of managing the
stream state as well as the integrity of the data and if there are any
problems, an exception is thrown testifying to the cause of the error.
Neat, he!
Now, class 'Person', is one of the classes being managed by
'io_base' which has been declared and implanted in the same manner
as the other classes in my library.
However, when compiling, or attempting to compile class 'Person' as
part of the rest of my library I get an error telling me that there is
a previous definition of 'class Person'. But this only happens if I
try to compile the entire library with it, library that is in source
code format still, as opposed of being in 'dll' or 'so' format.
This is a bug, obviously, and I will eventually find the bug; however
my question is, does anyone here know a better way to find this kind of
errors than to go line by line looking for the bug? Is there a
parameter in GCC that I can use so that the compiler is more specific,
or become more elaborate in what/where the error is?

Any help towards the solution of my problem will be most appreciated.

TIA.
 
N

Nick Keighley

Jamiil said:
This is not a question where the source code is important, it is not
important at all.

yet it is the source code that has a bug in it...

So don't expect to find answers to my questions in
the code; the answers will be in how the class interacts with the rest
of the program and/or how GCC can help me resolve my problem.

Having said that, I have a class called 'Person', and a class
called 'io_base', the purpose of 'io_base' is to implement file
input and output in a uniform manner for all my classes. All the user
of this class has to do is ask 'io_base' to open a file and then,
via the use of inserters and extractors, input or output data to and
from the file, as simple as that. The class takes care of managing the
stream state as well as the integrity of the data and if there are any
problems, an exception is thrown testifying to the cause of the error.
Neat, he!
Now, class 'Person', is one of the classes being managed by
'io_base' which has been declared and implanted in the same manner
as the other classes in my library.
However, when compiling, or attempting to compile class 'Person' as
part of the rest of my library I get an error telling me that there is
a previous definition of 'class Person'. But this only happens if I
try to compile the entire library with it, library that is in source
code format still, as opposed of being in 'dll' or 'so' format.
This is a bug, obviously, and I will eventually find the bug; however
my question is, does anyone here know a better way to find this kind of
errors than to go line by line looking for the bug? Is there a
parameter in GCC that I can use so that the compiler is more specific,
or become more elaborate in what/where the error is?

could you post the *exact* text of the error message(s)?
 
T

TB

Jamiil sade:
This is not a question where the source code is important, it is not
important at all. So don't expect to find answers to my questions in
the code; the answers will be in how the class interacts with the rest
of the program and/or how GCC can help me resolve my problem.

In your subject you state that there are bugs in your code, and
yet you proclaim the code to be of no significant value when trying
to find them.
Having said that, I have a class called 'Person', and a class
called 'io_base', the purpose of 'io_base' is to implement file
input and output in a uniform manner for all my classes. All the user
of this class has to do is ask 'io_base' to open a file and then,
via the use of inserters and extractors, input or output data to and
from the file, as simple as that. The class takes care of managing the
stream state as well as the integrity of the data and if there are any
problems, an exception is thrown testifying to the cause of the error.
Neat, he!

Not really said:
Now, class 'Person', is one of the classes being managed by
'io_base' which has been declared and implanted in the same manner
as the other classes in my library.
However, when compiling, or attempting to compile class 'Person' as
part of the rest of my library I get an error telling me that there is
a previous definition of 'class Person'. But this only happens if I
try to compile the entire library with it, library that is in source
code format still, as opposed of being in 'dll' or 'so' format.
This is a bug, obviously, and I will eventually find the bug; however
my question is, does anyone here know a better way to find this kind of
errors than to go line by line looking for the bug? Is there a
parameter in GCC that I can use so that the compiler is more specific,
or become more elaborate in what/where the error is?

Well, it said you're including more than one definition of 'Person'. Why
would you have to "go line by line" scavenging like a nfa? Isn't gcc
telling you where? What is gcc actually telling you?
 
R

roberts.noah

Jamiil said:
This is not a question where the source code is important, it is not
important at all. So don't expect to find answers to my questions in
the code....
Any help towards the solution of my problem will be most appreciated.

The answer is obvious: 42.
 
?

=?iso-8859-1?q?Stephan_Br=F6nnimann?=

TB said:
Well, it said you're including more than one definition of 'Person'. Why
would you have to "go line by line" scavenging like a nfa? Isn't gcc
telling you where? What is gcc actually telling you?

gcc just shows you where the duplicate definition is,
but it does not tell you to use header guards :)

Stephan
 
J

JustBoo

The answer is obvious: 42.

I thought it was 42 / (towel * bathtub) reflected in a mirror. Hmm...
I guess I was doing a "Rube Goldberg" there.

In the beginning the Universe was created. This has made a lot of
people very angry and has been widely regarded as a bad move.
- Douglas Adams
 
I

iftekhar

Jamiil
I guess the problem is with header file inclusion. are you including
the Person header in the io_base cpp and io_base header in the Person
cpp ? and does the person header has header guard? check these first.
please post the full gcc error

hope it helps
 
J

Jim Langston

Jamiil said:
This is not a question where the source code is important, it is not
important at all. So don't expect to find answers to my questions in
the code; the answers will be in how the class interacts with the rest
of the program and/or how GCC can help me resolve my problem.

Having said that, I have a class called 'Person', and a class
called 'io_base', the purpose of 'io_base' is to implement file
input and output in a uniform manner for all my classes. All the user
of this class has to do is ask 'io_base' to open a file and then,
via the use of inserters and extractors, input or output data to and
from the file, as simple as that. The class takes care of managing the
stream state as well as the integrity of the data and if there are any
problems, an exception is thrown testifying to the cause of the error.
Neat, he!
Now, class 'Person', is one of the classes being managed by
'io_base' which has been declared and implanted in the same manner
as the other classes in my library.
However, when compiling, or attempting to compile class 'Person' as
part of the rest of my library I get an error telling me that there is
a previous definition of 'class Person'. But this only happens if I
try to compile the entire library with it, library that is in source
code format still, as opposed of being in 'dll' or 'so' format.
This is a bug, obviously, and I will eventually find the bug; however
my question is, does anyone here know a better way to find this kind of
errors than to go line by line looking for the bug? Is there a
parameter in GCC that I can use so that the compiler is more specific,
or become more elaborate in what/where the error is?

Any help towards the solution of my problem will be most appreciated.

TIA.

Most likely is it because your include file for person does not have include
guards. That is, guards that prevent the same header from being included
twice. Simple at this:

person.h file:

#ifndef PERSON_H
#define PERSON_H

// header junk here

#endif

Now, if you have files that include files, and person.h gets included twice
in the same compilation unit, it won't cause an error because of the include
guards.

If this isn't the answer, the answer is obvious: 42.
 
J

Jamiil

Thanks for the prompt response.
Yes, that is the proble, but since each declaration file has 'inclusion
guards' I did not expect it to be a problem. What can I do to solve
this problem?
Again thanks so much!

Here is a posting with a little more info.

--- main.c ---
#include <cstdlib>
#include <iostream>
#include <string>
#include <limits.h>
#include <complex.h>

#include "../strtools/strtools.hpp"
#include "../gnu_io/gnu_io.hpp"
#include "person.hpp"

using namespace std;
void TestConstructors();
void TestingSetters();
int Write(jme::person&);
int main(int argc, char *argv[])
{
//TestConstructors();
TestingSetters();

system("PAUSE");

return EXIT_SUCCESS;
}

int Write(jme::person& obj){
try{
//file IO handler
----
}
void TestingSetters(){
//testing all the setters and getters for class Person
}
void TestConstructors(){
//Testing all the contructors for class Person
}

--- Person.hpp ----
#ifndef JME_PERSON_HPP
#define JEM_PERSON_HPP

#include <cstring>
#include <string>

#include "../exception/exception.hpp"
#include "../strtools/strtools.hpp"
#include "../name/name.hpp"
#include "../address/address.hpp"
#include "../email/email.hpp"
#include "../phone/phone.hpp"
#include "../url/url.hpp"
#include "../io_base/io_base.hpp" //<<<==== ??
#include "../gnu_io/gnu_io.hpp"
#include "../index/index.hpp"

#include <deque>
#include <algorithm>
#include <fstream>


namespace jme{

class Person{
// A whole bunch of variables and functions go here
};
}

--- person.cpp ---
#ifndef JME_PERSON_HPP
#include "person.hpp"
#endif
// A whole bunch of variable are assigned values through
// the uses of setters and getters.


--- io_base.hpp --
#ifndef JME_IO_BASE_H
#define JME_IO_BASE_H

#include <fstream>
#include <string>
#include "../exception/exception.hpp"
#include "../strtools/strtools.hpp"
#include "../name/name.hpp"
#include "../date/date.hpp"
#include "../money/money.hpp"
#include "../address/address.hpp"
#include "../email/email.hpp"
#include "../phone/phone.hpp"
#include "../url/url.hpp"
#include "../index/index.hpp"
#include "../person/person.hpp" //<<<<==== ??

Like most projects, this class belongs to a group library. When
testing the class as an isulated class, the program compiles without
any problems, however, when adding rest to the library to the test
program, the compiler complains sying that class Person has been
previously declared. I know, for a fact, that there is no redeclaration
of class Person. What I believe is happening is that I forgot to close
a bracket in a try block or anywhere else, but the compiler detects the
problem as being a redefined of the class Person.
This is the exact error code message:
Compiler: Default compiler
Building Makefile: "C:\Jamiil\dev\c++\jme\person\Makefile.win"
Executing make...
make.exe -f "C:\Jamiil\dev\c++\jme\person\Makefile.win" all
g++.exe -D__DEBUG__ -c main.cpp -o main.o -I"C:/GnuWin32/INCLUDE"
-I"C:/GnuWin32/INCLUDE/GTK-2.0" -I"C:/GnuWin32/INCLUDE/GLIB-2.0"
-I"C:/GnuWin32/INCLUDE/PANGO-1.0" -I"C:/GnuWin32/INCLUDE/CAIRO"
-I"C:/GnuWin32/INCLUDE/ATK-1.0" -I"C:/GnuWin32/INCLUDE/GTKGLEXT-1.0"
-I"C:/GnuWin32/LIB/GTK-2.0/INCLUDE"
-I"C:/GnuWin32/LIB/GLIB-2.0/INCLUDE"
-I"C:/GnuWin32/LIB/GTKGLEXT-1.0/INCLUDE"
-I"C:/GnuWin32/INCLUDE/LIBGLADE-2.0" -I"C:/GnuWin32/INCLUDE/LIBXML2"
-fexceptions -fverbose-asm -pg -g3

In file included from main.cpp:9:
person.hpp:26: error: redefinition of `class jme::person'
.../gnu_io/..\io_base\/../person/person.hpp:26: error: previous
definition of `class jme::person'

make.exe: *** [main.o] Error 1

Execution terminated


Thanks!!
 

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,754
Messages
2,569,525
Members
44,997
Latest member
mileyka

Latest Threads

Top