Reputation: 17
I am using geany (code::blocks wouldnt run my programs) as a compiler to compile a simple c++ program with one class. I am on Linux Mint 17 on a Dell Vostro 1500. Compiling works fine with both .cpp files, but the header file gives this error:
gcc -Wall "Morgan.h" (in directory: /home/luke/Documents/Coding/Intro#2)
Morgan.h:5:1: error: unknown type name ‘class’
class Morgan
^
Morgan.h:6:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
{
^
Compilation failed.
This is the main.cpp :
#include <iostream>
#include "Morgan.h"
using namespace std;
int main()
{
Morgan morgObject;
morgObject.sayStuff();
return 0;
}
This is the Header file (Morgan.h):
#ifndef MORGAN_H
#define MORGAN_H
class Morgan
{
public:
Morgan();
void sayStuff();
protected:
private:
};
#endif // MORGAN_H
And this is the class (Morgan.cpp):
#include <iostream>
#include "Morgan.h"
using namespace std;
Morgan::Morgan()
{
}
void Morgan::sayStuff(){
cout << "Blah Blah Blah" << endl;
}
I really do not know what is going wrong, so any help would be appreciated. I copy and pasted the same code into a windows compiler and it worked fine, so it might just be the linux.
also when I run the main.cpp this is what shows: "./geany_run_script.sh: 5: ./geany_run_script.sh: ./main: not found"
Upvotes: 0
Views: 168
Reputation: 1473
Your issue is that you are compiling C++ code with a C compiler (GCC). The command you are looking for is g++
. The complete command that would compile your code is:
g++ -Wall -o run.me main.cpp Morgan.cpp
If a file is included (In your case the Morgan.h
file, you do not need to explicitly compile it. )
Upvotes: 2
Reputation: 3779
You don't compile .h files. Try g++ -Wall main.cpp Morgan.cpp
Upvotes: 3