I am using codeblock and my compiler setting is [-std=c++0x].
I created a simple project with the following code:
main.cpp
#include <iostream>
#include "Cat.h"
using namespace std;
int main() {
Cat action;
action.meow();
action.jump();
return 0;
}
Cat.h
#ifndef CAT_H_INCLUDED
#define CAT_H_INCLUDED
class Cat {
public:
void meow();
void jump();
};
#endif // CAT_H_INCLUDED
CatProcess.cpp
#include <iostream>
#include "Cat.h"
using namespace std;
void Cat::meow() {
cout << "meow" << endl;
}
void Cat::jump() {
cout <<"jump" << endl;
}
Error messages:
When I build and run the entire project, this error shows up on main.cpp line 8 on my IDE:
undefined reference to 'Cat::meow()'
When I build and run CatProcess.cpp, this error shows up:
error: Cannot find target for file
Build log:
mingw32-g++.exe -Wall -fexceptions -g -std=c++0x -c C:\Users\Im_so\Documents\CodeBlock_Projects\ClassesForCats\main.cpp -o obj\Debug\main.o
obj\Debug\main.o: In function 'main': C:/Users/Im_so/Documents/CodeBlock_Projects/ClassesForCats/main.cpp:8: undefined reference to 'Cat::meow()'
C:/Users/Im_so/Documents/CodeBlock_Projects/ClassesForCats/main.cpp:9: undefined reference to 'Cat::jump()'
collect2.exe: error: ld returned 1 exit status