When i create classes they work perfectly when the class definition is in main.cpp. But when i try make classes with the header and source files separately the compiler cannot seem to find the source file and comes up with "undefined reference to className::classMemberFunction()" .
Heres an example :
The header file:
#ifndef EXAMPLE_H
#define EXAMPLE_H
#include <iostream>
class Example
{
public:
Example();
};
#endif // EXAMPLE_H
The source file:
#include "Example.h"
Example::Example()
{
std::cout << "This isn't working ):";
}
I can compile the program if I go settings-->compiler-->linker setings, and then under link library click add and add the pathway to the source file.
The only problem is that i have to then delete the added link library path to be able to compile other programs and then i have to reset it to compile the class program. I have made sure that all the files are in the same directory.
Please can someone tell me if there is a permanent setting that i can change to fix this, its really annoying me.
Apparently this does not happen with the older 12.11 version, but that gives me another problem - something about the GNU GCC compiler.
Also im quite a noob in programming, thought it should be mentioned.
use command:
g++ main.cpp example.cpp -o test_example
replace here main.cpp example.cpp by names of your files.
There are many a beautiful papers for newbies about gcc and it's options. Google helps!