C++ Compiling Help!!! SOS !!!

Hi All,

I have a program to simulate the Book Keeping of a parking lot.

I have attached four files :

Main.txt (Main.cpp)
parklot.txt (header file)
cardata.txt (header file)
clock.txt (header file)

I am having difficulty compiling it, as while compiling I get an error and it does not recognize the clock header file. I have worked tremendously for a while on it, So if anyone can help me in compiling it, I would be extremely grateful!!!!

All hail the programmers! (P.S: I used Dev C++ to work on it, lemme know if I need to use Turbo C++).

Thanks a bunch....

Comments

  • Hi,

    Your header guard is incomplete. It should be:

    [code]
    #ifndef _clock_H_
    #define _clock_H_

    // ... Rest of your code here.

    #endif
    [/code]

    The [italic]#endif[/italic] preprocessor directive has to be preceeded by one of the [italic]#if[/italic] conditional preprocessor directives.

    You should use a header guard in every header.

    Regards,
    Michael
    michaelgallagher.au@gmail.com
  • #endif _clock_H_

    Note that this is not allowed in standard C/C++. The correct way is to write as MichaelAU showed. Though you can add the name of the header guard as a comment:

    #ifndef _clock_H_
    #define _clock_H_
    ...
    #endif /* _clock_H_ */
  • Hi Michael,

    This is what I get when I try to compile it. I have changed the clock.h file too!! :-(

    Compiler: Default compiler
    Executing g++.exe...
    g++.exe "C:Documents and SettingskumamithDesktopSimNew Foldermain.cpp" -o "C:Documents and SettingskumamithDesktopSimNew Foldermain.exe" -I"C:Dev-Cpplibgccmingw323.4.2include" -I"C:Dev-Cppincludec++3.4.2ackward" -I"C:Dev-Cppincludec++3.4.2mingw32" -I"C:Dev-Cppincludec++3.4.2" -I"C:Dev-Cppinclude" -L"C:Dev-Cpplib"
    In file included from C:/Dev-Cpp/include/c++/3.4.2/backward/iostream.h:31,
    from C:Documents and SettingskumamithDesktopSimNew Foldermain.cpp:17:
    C:/Dev-Cpp/include/c++/3.4.2/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the header for the header for C++ includes, or instead of the deprecated header . To disable this warning use -Wno-deprecated.
    C:Documents and SettingskumamithDesktopSimNew Foldermain.cpp:22:64: clock.h: No such file or directory
    C:Documents and SettingskumamithDesktopSimNew Foldermain.cpp:273: error: ISO C++ forbids declaration of `InitParkingLot' with no type

    C:Documents and SettingskumamithDesktopSimNew Foldermain.cpp: In function `int main(int, char**)':
    C:Documents and SettingskumamithDesktopSimNew Foldermain.cpp:609: error: `Clock' undeclared (first use this function)
    C:Documents and SettingskumamithDesktopSimNew Foldermain.cpp:609: error: (Each undeclared identifier is reported only once for each function it appears in.)
    C:Documents and SettingskumamithDesktopSimNew Foldermain.cpp:609: error: expected `;' before "BigBen"

    C:Documents and SettingskumamithDesktopSimNew Foldermain.cpp:659: error: `BigBen' undeclared (first use this function)

    Execution terminated


  • Hi Lundin.. Please check the post below.
  • Ok...

    I have minimized all errors to only this.

    ISO C++ forbids declaration of `InitParkingLot' with no type.
    Execution Terminated.

    Should I change it to Main.c instead of .cpp??
    Should I use Borland C++ Builder instead of Dev C++??

    I have uploaded my main.c here as a text file (zipped). I need this executable up and running. Thank you Michael/Lundin for all your help!! (Bowing Down) :-)

    xx
  • Okaaayyy... I gave the type int to InitParkingLot.

    I also added -ansi -pedantic -Wall -Wno-deprecated to the compiler command.

    Now this is what i get. The header is included in the first file I uploaded.

    Compiler: Default compiler
    Building Makefile: "C:Documents and SettingskumamithDesktopSimNew FolderSIMULATORFINALMakefile.win"
    Executing make...
    make.exe -f "C:Documents and SettingskumamithDesktopSimNew FolderSIMULATORFINALMakefile.win" all
    g++.exe -c main.cpp -o main.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -ansi -pedantic -Wall -Wno-deprecated

    main.cpp: In member function `CarData* ParkingLot::FindPlate(int)':
    main.cpp:73: warning: unused variable 'i'

    main.cpp:74: warning: unused variable 'FoundFlag'

    main.cpp: In constructor `ParkingLot::ParkingLot()':
    main.cpp:206: warning: unused variable 'Hour0'
    main.cpp:207: warning: unused variable 'Min0'

    g++.exe main.o -o "Sim.exe" -L"C:/Dev-Cpp/lib"

    main.o(.text+0x1c2):main.cpp: undefined reference to `Clock::Clock()'
    main.o(.text+0x4a7):main.cpp: undefined reference to `Clock::Clock()'
    main.o(.text+0x4cd):main.cpp: undefined reference to `Clock::Hours()'
    main.o(.text+0x4e1):main.cpp: undefined reference to `Clock::Mins()'
    main.o(.text+0x55f):main.cpp: undefined reference to `Clock::Hours()'
    main.o(.text+0x573):main.cpp: undefined reference to `Clock::Mins()'
    collect2: ld returned 1 exit status

    make.exe: *** [Sim.exe] Error 1

    Execution terminated
  • Your h-file #includes should look like this:

    #include
    #include
    #include
    #include
    #include
    #include "clock.h"

    using namespace std;
  • Yup it worked like a charm. But now, I get a linker error undefined reference to :

    Clock::Clock()
    Clock::Hours()
    Clock::Mins()

    So I added them to the header, since I had to define the constructor.

    Now, I get this:

    Compiler: Default compiler
    Building Makefile: "C:Dev-CppsimulMakefile.win"
    Executing make clean
    rm -f main.o simul.exe

    g++.exe -c main.cpp -o main.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include"

    In file included from main.cpp:10:
    clock.h:21: error: expected `;' before "Clock"

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

    Execution terminated.

    (At wits end... :-()



  • Hi,

    Please post your new [italic]clock.h[/italic].

    Regards,
    Michael
    michaelgallagher.au@gmail.com
  • // clock.H

    #ifndef _clock_H_
    #define _clock_H_

    class Clock {
    public:
    Clock(); // constructor

    int Hours(); // return current hours
    int Mins(); // return mins in current time

    Clock::Clock()
    Clock::Hours()
    Clock::Mins()

    private:
    int hours, mins;
    };



    #endif /* _clock_H_ */
  • Also, this is the makefile I was provided from a friend. Who got his to work.

    C++ = c++
    OPTIONS = -g
    .SUFFIXES: .o .C
    LIBPATH = /u/madonna1/faculty/cs270/public/programs/prog3
    INCLUDES = -I/u/madonna1/faculty/cs270/public/programs/prog3


    .C.o:
    $(C++) $(CCFLAGS) $(INCLUDES) $(OPTCCFLAGS) -c $<


    .cc.o:
    $(C++) $(CCFLAGS) $(INCLUDES) $(OPTCCFLAGS) -c $<

    SRC= main.C clock.C


    OBJ= main.o $(LIBPATH)/clock.o

    teststrings: $(OBJ)
    $(C++) $(OPTIONS) $(INCLUDES) -o sampleProg3 $(OBJ)

    clean:
    rm -f sampleProg3 a.out *.o core


    depend:
    $(C++) -M ${INCLUDE} ${DEFINES} ${SRC} > makedep
    echo '/^# DO NOT DELETE THIS LINE/+1,$$d' >eddep
    echo '$$r makedep' >>eddep
    echo 'w' >>eddep
    cp Makefile Makefile.bak
    ed - Makefile < eddep
    rm eddep makedep
    # DO NOT DELETE THIS LINE -- make depend uses it
    main.o : main.C clock.H
    clock.o : clock.H

  • Hi,

    The following lines are incorrect.

    [code]
    Clock::Clock()
    Clock::Hours()
    Clock::Mins()
    [/code]

    The constructor and functions [italic]Hours[/italic] and [italic]Mins[/italic] were already declared. Also, the above declarations lacked the required semicolon.

    I am no longer used to reading Makefiles, but I think the last line regarding [italic]clock.o[/italic] should have [italic]clock.C[/italic] listed as a prerequisite after the colon.

    The most likely reasons you had undefined reference errors to the [italic]Clock[/italic] functions was because [italic]clock.o[/italic] was not being correctly linked or [italic]clock.o[/italic] was being linked, but you forgot to put [italic]Clock::[/italic] before the function name declarations in [italic]clock.C[/italic]. If the problem was linking, you might like to look at Code::Blocks. It is an easy to use, cross-platform IDE with its own very stable build system. If you do want to use it, download a nightly build.

    http://www.codeblocks.org

    Regards,
    Michael
    michaelgallagher.au@gmail.com
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories