This is my first post and I'm sort of new to programming and figured joining this forum to try and get some help. So please excuse me if I happen to miss something.

Task:
- Create a cylinder specified by my program with the radius and height
- Which will calculate the surface area and volume of the cylinder

Issue:
- I'm creating a cylinder program that isn't compiling correctly.
- Yes this is for a college course I'm not asking for the answer but just if anyone can help me figure out what I'm doing wrong...

Error:
- Undefined symbols:
"_main", referenced from:
start in crt1.10.6.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

Utilizing:
- Mac OSX 10.6
- Compiling in Terminal

***Main***

#include <iostream> 
#include "cylinder.h"

using namespace std;

int main()
{
    Cylinder CylinderOne(10.0, 10.0); 
    
    cout << "Cylinder 1 Radius: " << CylinderOne.getRadius() << endl;
    cout << "Cylinder 1 Height: " << CylinderOne.getHeight() << endl; 

    cin.get();
    return 0;
}

***Class***

#include "cylinder.h"

const double PI = 3.14159;

// Constructors 
Cylinder::Cylinder()
{
    radius = 0;
    height = 0;
}
Cylinder::Cylinder(double r, double h)
{
    radius = r; 
    height = h;  
}

// Accessors
double Cylinder::getRadius()
{
    return radius; 
}
double Cylinder::getHeight()
{
    return height;
}

// Setters
void Cylinder::setRadius(double r)
{
    radius = r; 
}
void Cylinder::setHeight(double h)
{
    height = h; 
}

// Calculations 
double Cylinder::area()
{
    return volume() * 2 * PI * radius * radius;
}
double Cylinder::volume()
{
    return PI * radius * radius * height; 
}

***Header***

using namespace std; 

class Cylinder
{
public:

    // Constructors
	Cylinder();
	Cylinder(double r, double h);

    // Accessors
	double getRadius();
	double getHeight();
	void setRadius(double r);
	void setHeight(double h);
	double area();
	double volume(); 

private:
	double radius;
	double height;
};

- Compiling in Terminal

What is the command you are using to compile? You need to put both .cpp files in the command. g++ myclass.cpp mymain.cpp -o myprogram (assuming you're using gcc).

Edited 5 Years Ago by jonsca: n/a

Jonsca! SAVIOR! Thank you I have been having this issue for hours.

I do utilize the gcc... (not sure what you mean by that) but I do compile utilizing the g++. I was able to compile my program and have it run correctly. I appreciate the feedback. I literally just posted this thread not 10 minutes ago.

gcc refers to the GNU compiler collection (it's also the command to invoke the C compiler, which makes it a bit confusing).

Glad you got it working! (look into some of the other switches available with that compiler, particularly -Wall to have it display the highest level of warnings.

See I'm not too familiar with the Terminal in mac. I'm only aware of some basic commands and what I normally am using in class would be Microsofts Visual basics 2008. So I am kind of jumping platforms a bit although I would really like to learn how to use my Xcode, just haven't gotten to it yet...

I'll see if I can come across more commands and maybe that should help.

Although thanks again. I do appreciate your time. I plan on utilizing this forum more often. So that I can educate myself in programming a bit better and so far it has been very helpful.

I think you should recheck your area() function. You are definitely not calculating the cylinder's surface area that way.

Ah I do see the issue. I was too worried in trying to compile the program that I kind of just did that.

Thank you for pointing that out.

Should look something more like this:

Cylinder:area()
{
return 2 * PI * radius * radius + 2 * PI * radius * height; 
}
This question has already been answered. Start a new discussion instead.