Hi, So below are 3 files I have for a multifile project and i keep getting an error of:
Undefined symbols for architecture x86_64: "_main", referenced from: implicit entry/start for main executable ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
#include <iostream>
#include "fraction.cpp"
using namespace std;
int main()
{
fraction f1(9,8); //calling a parameterized class constructor
fraction f2(2,3); //calling a parameterized class constructor
fraction result; //calling a default class constructor
fraction f3; //calling a default class constructor
cout << "The result starts off at ";
result.print(); //calling an observer function
cout << endl;
cout << "The product of ";
f1.print();
cout << " and ";
f2.print();
cout << " is ";
result = f1.MultipliedBy(f2); //a class binary operation - function
result.print();
cout << endl;
f3 = result; //assignment
if (f2.isGreaterThan(f3)){ //a class relational expression - boolean operation/function
f2.print();
cout <<" is greater than ";
f3.print();
cout<<endl;
} else {
f2.print();
cout <<" is less than ";
f3.print();
cout<<endl;
}
cout << "The sum of ";
f1.print();
cout << " and ";
f2.print();
cout << " is ";
result = f1.AddedTo(f2); //a class binary operation - function
result.print();
cout << endl;
cout << "The difference of ";
f1.print();
cout << " and ";
f2.print();
cout << " is ";
result = f1.Subtract(f2); //a class binary operation - function
result.print();
cout << endl;
if (f1.isEqualTo(f2)){ //a class relational expression - boolean operation/function
cout << "The two fractions are equal." << endl;
} else {
cout << "The two fractions are not equal." << endl;
}
fraction f4(12, 8);
fraction f5(202, 303);
result = f4.DividedBy(f5); //a class binary operation - function
cout << "The quotient of ";
f4.print();
cout << " and ";
f5.print();
cout << " is ";
result.print();
cout << endl;
system ("PAUSE");//exclude statement if not using Dev-C++
return 0;
}
I dont understand what you @jaybob66 mean by include the "fraction.h" I am new to programming and need a bit more specific help on this topic. Right now under my project folder I have the three files so it goes
Project Name
-fraction.h
Fraction folder
main.cpp
Client folder
main.cpp
Products folder.
#include <iostream>
#include "fraction.h"
using namespace std;
int main()
{
fraction f1(9,8); //calling a parameterized class constructor
fraction f2(2,3);
fraction result; //calling a default class constructor
const fraction f3(12, 8);
const fraction f4(202, 303);
fraction f5,f6;
cout<<"C++ CLASS MULTI-FILE PROJECT"<<endl;
cout<<"Client.cpp - testing a fraction class implementation\n";
cout<<"----------------------------------------------------\n\n";
cout << "The result object starts off at ";
result.showFraction(); //calling a void "observer" function
cout << endl;
cout<<"\nArithmetic operations with fraction objects stored in the results class object\n";
cout<<"------------------------------------------------------------------------------\n\n";
cout << "The sum of ";
f1.showFraction();
cout << " and ";
f2.showFraction();
cout << " is ";
result = f1.AddedTo(f2); //a class binary operation - a value-returning "observer" function
result.showFraction();
cout << endl;
cout << "The difference of ";
f1.showFraction();
cout << " and ";
f2.showFraction();
cout << " is ";
result = f1.Subtract(f2); //a class binary operation - a value-returning "observer" function
result.showFraction();
cout << endl;
cout << "The product of ";
f1.showFraction();
cout << " and ";
f2.showFraction();
cout << " is ";
result = f1.MultipliedBy(f2); //a class binary operation - a value-returning "observer" function
result.showFraction();
cout << endl;
result = f3.DividedBy(f4); //a class binary operation - a value-returning "observer" function
cout << "The quotient of ";
f3.showFraction();
cout << " and ";
f4.showFraction();
cout << " is ";
result.showFraction();
cout << endl;
cout<<"\nInput and Output operations for two new class objects\n";
cout<<"-----------------------------------------------------\n\n";
f5.getFraction(); //a class input operation - a transformer or setter function
f5.showFraction(); //a class output operation - an observer or getter function
cout<<endl<<endl;
f6.getFraction();
f6.showFraction();
cout<<endl<<endl;
cout<<"\nA Boolean operation comparing two class objects\n";
cout<<"------------------------------------\n\n";
if (f5.isGreaterThan(f6)){ //a class relational expression - boolean operation/function
f5.showFraction();
cout <<" is greater than ";
f6.showFraction();
cout<<endl;
} else {
f5.showFraction();
cout <<" is less than ";
f6.showFraction();
cout<<endl;
}
cout<<"\n---------------------------------------------------------\n";
cout<<"\nFraction class implementation test now successfully concluded\n";
Otherwise tell us the specific command line commands you use for compiling or show the full build log in the IDE you are using, since this is a linker error. (but I have not tried to compile the code myself since it seems quite plain).
I think there are online compilers out there that have support for multiple files, like onlinegdb.com, try your code in that.
Since this is a trivial problem that should be learned quickly, you should stop bothering people with your problems, and look into a tutorial which is a step above cplusplus's minimal tutorial (since I don't believe it shows any examples of setting up your compiler or IDE), try lazyfoo's website (this steps into graphical programming, but I believe it has a lot to teach in a short context that anyone can understand), or get an entry level book which has compilable examples.
Also I see you are not guarding your headers, use the ifdef+define+endif combo you may have seen before, or use #pragma once at the top of the header file. I hope you only took it off while copy and pasting because you thought it didn't look important. But it is not the cause of your error.
Also next time use the <> button while editing your text to insert code formatting (I find it doesn't work while creating a topic in my browser, you gotta memorize the [code] code here [/code], and read the beginners sticky once, because shouldn't make a topic called "Help with Programming".
Now, your actual problem that the compiler/linker is complaining about, is that it can't find "main" so we need to check that you told it to build it.
when you build your program all of the .cpp files (THAT YOU SPECIFY) get converted to some form of machine code and stored in .o/.obj files. If all the cpp files compile ok, the next step is to "link" all of the .o/.obj files into an exe
so in all of the files that the linker was told to link, it could not find "main" but we know it exists because its in the source code client.cpp so have to presume that the linker wasn't told about client.o/.obj, is there a client.o/.obj file in your folders?
so, what we need from you...
what IDE/compiler are you using to create/build your c++ project? Without that info we can't really say what you should check.
also post the copied output of your build so we can see the errors "in situ"