I am currently learning C++. I am going through the book "Beginning c++" from Wrox Press. All the stupid little programs I have written so far have worked flawlessly. But now I am in the OOP section and they are dividing up the code into different files. The program I am having problems with has a class to make a 'box' object. I have 3 files, Box.h, Box.cpp, & UseBox.cpp. I copied the code straight fromt he book. Here it is.
The author has not discussed how to write makefiles yet so I read some online tutorials and came up with this...
When I do 'make' I get...
g++ -g -Wall -c UseBox.cpp
g++ -g -Wall -o UseBox.o Box.o
/usr/lib/gcc-lib/i586-suse-linux/3.3.3/../../../crt1.o(.text+0x18): In function `_start':
../sysdeps/i386/elf/start.S:98: undefined reference to `main'
collect2: ld returned 1 exit status
make: *** [MyProj] Error 1
Anyone have any ideas? I have been searching google endlessly but have not found anything useful. I'm guessing it is some stupid error in my makefile.
Much thanks for any help.
I appologize for the total noob question.
Cory Tobin
Code:
// Box.h
#ifndef BOX_H
#define BOX_H
class Box
{
public:
double length;
double breadth;
double height;
// Constructor
Box(double lengthValue, double breadthValue, double heightValue);
// Function to calculate volume of box
double volume();
};
#endif
Code:
// Box.cpp
#include <iostream>
#include "Box.h"
using namespace std;
// Constructor definition
Box::Box(double lengthValue, double breadthValue, double heightValue)
{
cout << "Box constructor called" << endl;
length = lengthValue;
breadth = breadthValue;
height = heightValue;
}
// Function to calculate the volume of a box
double Box::volume()
{
return length * breadth * height;
}
Code:
// UseBox.cpp - Program to use class Box
#include <iostream>
#include "Box.h"
using namespace std;
int main()
{
Box firstBox(80.0, 50.0, 40.0);
cout << endl;
cout << "Size of the first box object is "
<< firstBox.length << " by "
<< firstBox.breadth << " by "
<< firstBox.height
<< endl;
cout << "Volume of first Box object is " << firstBox.volume()
<< endl;
return 0;
}
Code:
CXX = g++
CCFLAGS = -g -Wall
MyProj: UseBox.o Box.o
${CXX} ${CCFLAGS} -o UseBox.o Box.o
Box.o: Box.cpp Box.h
${CXX} ${CCFLAGS} -c Box.cpp
UseBox.o: UseBox.cpp Box.cpp Box.h
${CXX} ${CCFLAGS} -c UseBox.cpp
When I do 'make' I get...
g++ -g -Wall -c UseBox.cpp
g++ -g -Wall -o UseBox.o Box.o
/usr/lib/gcc-lib/i586-suse-linux/3.3.3/../../../crt1.o(.text+0x18): In function `_start':
../sysdeps/i386/elf/start.S:98: undefined reference to `main'
collect2: ld returned 1 exit status
make: *** [MyProj] Error 1
Anyone have any ideas? I have been searching google endlessly but have not found anything useful. I'm guessing it is some stupid error in my makefile.
Much thanks for any help.
I appologize for the total noob question.
Cory Tobin