Reputation: 9
I used g++ compiler and used terminal for compiling single c++ files and projects as well (under project I mean files in the same dir, but not a real Xcode project). I had no problems, but I upgraded to OS X Mavericks, and from that point, I am only able to compile single files. After that, I installed Xcode 5.0.1, and installed command line tools, but didn't solve my problem.
So now I am using OS X 10.9 Mavericks Xcode 5.0.1 (5A2053).
I thought, the problem is with my source code, but now I've made a really simple program, but I get the same error:
Steve-MacBook:test szaboistvan$ g++ -o main main.cpp
Undefined symbols for architecture x86_64:
"Myclass::geta()", referenced from:
_main in main-0bDtiC.o
"Myclass::getb()", referenced from:
_main in main-0bDtiC.o
"Myclass::Myclass()", referenced from:
_main in main-0bDtiC.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The files of the project: main.cpp
#include <iostream>
#include "Myclass.h"
using namespace std;
int main(){
Myclass one;
cout<<one.geta()<<endl<<one.getb()<<endl;
return 0;
}
Myclass.h
#include <iostream>
class Myclass
{
private:
int a;
double b;
public:
Myclass();
int geta();
double getb();
};
Myclass.cpp
#include <iostream>
#include "Myclass.h"
using namespace std;
Myclass(){
int a=5;
double b=3.0;
}
int geta(){
return a;
}
double getb(){
return b;
}
Thank you in advance!
Upvotes: 0
Views: 370
Reputation: 3004
Unless I am being thick (hint, I am not), you havent implemented
MyClass::geta()
.
Instead, you implemented a function called geta
Your class methods should be like:
MyClass::Myclass()
{
int a=5;
double b=3.0;
}
int MyClass::geta()
{
....
}
etc
In addition, you cant be compiling MyClass.cpp
, since the code in there is not valid.
Upvotes: 1