954,498 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Compiling Errors

im new with C++ . i was in java but now im learning C++ and i am not very good at it . i am making a program about spam and ham emails . i have all the files in the same directory . i created Ergasia1.cpp , Ergasia1.h , Feature.cpp , Feature.h
but when i compile Ergasia1.cpp i got errors like :

1. " In file included from Ergasia1.cpp "
2. " Ergasia1.h [Warning] extra tokens at end of #endif directive "
3. "Feature.h [Warning] extra tokens at end of #endif directive " (after this error there are several errors like this " [Linker error] undefined reference to `Feature::getDescription()' "
4. " Feature.h ld returned 1 exit status "

and when i compile Feature.cpp i got errors like :

1. " In file included from Feature.cpp "
2. " [Linker error] undefined reference to `WinMain@16' "
3. " Feature.h ld returned 1 exit status "

Ergasia1.cpp

#include "Ergasia1.h"
#include "Feature.h"

using namespace std;

Ergasia1::Ergasia1()
{
#ifdef DEVEL
	tst= "../../";
#else 
	tst= "./";
#endif

	bool AllOK= FillvsKeys();
	if (AllOK) {
		GetFiles(LING);
		GetFiles(SPAM);
		ShowData();
	}
	else 
		cout << "Incorrect Installation!" << endl;
}

const void Ergasia1::AnalyzeFile(const string fn) {
	string fname= fn.substr(tst.length());
	size_t pos= fname.find_first_of("/");
	string kind= "";
	if (pos != string::npos)
		kind= fname.substr(0, pos);
	int KeywordsFound= 0;
	ifstream ifs(fn.c_str());	
  if (ifs.is_open()) {
		n++;
		vector<Feature> vf; 

		while (! ifs.eof()) {
			string line;
			getline(ifs, line);
			
			for (unsigned int i= 0; i < vsKeys.size(); i++) {
				string key= vsKeys[i];
				if (line.find(key) != string::npos) {
					bool found= false;
					for (unsigned int j= 0; j < vf.size(); j++) 
						if (vf[j].getDescription().compare(key) == 0) {

							int x= vf[j].getFrequency();
							vf[j].setFrequency(++x);
							found= true;
							break;
						}
					if (! found) {
						
						Feature *f= new Feature(i, 1, key);
						vf.push_back(*f);
						KeywordsFound++; 
					}
				}				
			}
    }
    ifs.close();
		ostringstream osst;
		osst << "<message file=\"" << fname <<"\" category=\"" << kind << "\" features=\"" << KeywordsFound << "\">";
		vsStream.push_back(osst.str());
		osst.flush();
		for (unsigned int i= 0; i < vf.size(); i++) {
			ostringstream ossb;	
			ossb << "<feature id=\"" << vf[i].getId() << "\" freq=\"" << vf[i].getFrequency() << "\"> " << vf[i].getDescription() << " </feature>";
			vsStream.push_back(ossb.str());
			ossb.flush();
		}
		ostringstream osse;
		osse << "</message>";
		osse.flush();
		
	}
}

const void Ergasia1::GetFiles(const string Kind) {
	string s= tst + Kind + FILENAME;//"_filenames.txt";
	ifstream ifs(s.c_str());	
  if (ifs.is_open()) {
    while (! ifs.eof()) {
      string line;
			getline(ifs, line);
			AnalyzeFile(tst + line);
    }
    ifs.close();
  }
}

const bool Ergasia1::FillvsKeys() {
	bool result= true;
	string s= tst + KEYWORDS;
	n= 0;
	ifstream ifs(s.c_str());	
  if (ifs.is_open()) {
    while (! ifs.eof()) {
      string line;
			getline(ifs, line);
			vsKeys.push_back(line);
    }
	}
	else
		result= false;
  ifs.close();
	return result;
}

const void Ergasia1::ShowData() {
	cout << "<messagecollection messages=\"" << n << "\">" << endl;
	for(unsigned int i= 0; i < vsStream.size(); i++)
		cout << vsStream[i] << endl;
	cout << "</messagecollection>" << endl;
}

int main(int argc, char **argv) {
	Ergasia1 e;
	return 0;
}


Ergasia.h

#include <fstream>
#include <string>
#include <vector>
#include <iostream>
#include <sstream>

#ifdef _DEBUG
#define DEVEL
#endif

using namespace std;

#ifndef FILENAME
#define FILENAME "_filenames.txt";
#endif

#ifndef KEYWORDS
#define KEYWORDS "keywords.txt"
#endif

#ifndef LING
#define LING "ling"
#endif

#ifndef SPAM
#define SPAM "spam"
#endif

#ifndef ERGASIA1_H
#define ERGASIA1_H

class Ergasia1
{
private:
	int n;	
	string tst;
	//static const string FileName;
	vector<string> vsKeys;
	vector<string> vsStream;
	const void AnalyzeFile(const string fn);
	const void GetFiles(const string Kind);
	const bool FillvsKeys();
	const void ShowData();
	
public:
	Ergasia1();
}
#endif 
//ERGASIA1_H

int main(int argc, char **argv);

Feature.cpp

#include "Feature.h"

void Feature::setId(int i) {
	Id= i;
}

void Feature::setFrequency(int f) {
	Frequency= f;
}

void Feature::setDescription(const string d) {
	Description= d;
}

int Feature::getId() {
	return Id;
}

int Feature::getFrequency() {
	return Frequency;
}

string Feature::getDescription() {
	return Description;
}

Feature::Feature(int i, int f, const string d) {
	setId(i);
	setFrequency(f);
	setDescription(d);
}

Feature.h

#include <iostream>
using namespace std;
#ifndef FEATURE_H
#define FEATURE_H

class Feature {
private:
	int Id;
	int Frequency;
	string Description;
public: 
	void setId(int i);
	void setFrequency(int f);
	void setDescription(const string d);
	int getId();
	int getFrequency();
	string getDescription();
	Feature(int i, int f, const string d);
}
#endif 
//FEATURE_H

thats the files i created . any help will be appreciate . thanks in advance my friends .

konefsta
Newbie Poster
9 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
 

Just looking briefly, I see one error on line #14 of ergasia.h:

#define FILENAME "_filenames.txt";
Clinton Portis
Practically a Posting Shark
833 posts since Oct 2005
Reputation Points: 237
Solved Threads: 118
 

i still have the same errors . :-/
any other ideas ?

konefsta
Newbie Poster
9 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
 

Seem to be missing semicolons after your class declarations in the headers:

class Feature {
private:
	int Id;
	int Frequency;
	string Description;
public: 
	void setId(int i);
	void setFrequency(int f);
	void setDescription(const string d);
	int getId();
	int getFrequency();
	string getDescription();
	Feature(int i, int f, const string d);
};     <-------------- (and in your other header too)


Oh yeah, and get rid of that declaration of main in the header file. Keep the one in the cpp file.

jonsca
Quantitative Phrenologist
Team Colleague
5,621 posts since Sep 2009
Reputation Points: 1,165
Solved Threads: 581
 

i still have the same errors :(

konefsta
Newbie Poster
9 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
 

i am thinking , is it possible that i am missing a file or something ?

konefsta
Newbie Poster
9 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
 

You need to compile them at the same time as they are dependent on one another e.g., g++ -o myprogram ergasia.cpp feature.cpp depending on what compiler you are using. I suppose you could compile them separately to .o files and link them together but doing it in one step is easier.

jonsca
Quantitative Phrenologist
Team Colleague
5,621 posts since Sep 2009
Reputation Points: 1,165
Solved Threads: 581
 

how can i compile them in the same time ? i am using Dev-C++ and wxDev-C++

konefsta
Newbie Poster
9 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
 
konefsta
Newbie Poster
9 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
 

I haven't used it since it's infancy in the 90's (dating myself here,I'm sure it's matured since then), but basically you need to start a console project (screenshot here: http://en.wikiversity.org/wiki/Installing_and_using_Dev-C%2B%2B ) and incorporate those headers and cpp files into the project by right clicking the project name.
I'm sure there are plenty of other folks on here who know Dev-C++ like the back of their hand, so post back if you're still having trouble.

jonsca
Quantitative Phrenologist
Team Colleague
5,621 posts since Sep 2009
Reputation Points: 1,165
Solved Threads: 581
 
I haven't used it since it's infancy in the 90's (dating myself here,I'm sure it's matured since then), but basically you need to start a console project (screenshot here: http://en.wikiversity.org/wiki/Installing_and_using_Dev-C%2B%2B ) and incorporate those headers and cpp files into the project by right clicking the project name. I'm sure there are plenty of other folks on here who know Dev-C++ like the back of their hand, so post back if you're still having trouble.


seemed nice idea , i tried it , still got the same errors . i just cant figure out whats my mistake .

konefsta
Newbie Poster
9 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
 

Go through your files that I uploaded back and make sure that I didn't make any changes that you didn't make. Otherwise these do compile on my machine, albeit giving a program that outputs "Incorrect installation!"

If you know where you're going, look for the command line tools that are part of Mingw included in your Dev-C++ and try to compile it on the command line (my "g++ .... " from before).

Attachments ergasia1.cpp (2.64KB) ergasia1.h (0.77KB) feature.cpp (0.45KB) feature.h (0.38KB)
jonsca
Quantitative Phrenologist
Team Colleague
5,621 posts since Sep 2009
Reputation Points: 1,165
Solved Threads: 581
 

Go through your files that I uploaded back and make sure that I didn't make any changes that you didn't make. Otherwise these do compile on my machine, albeit giving a program that outputs "Incorrect installation!"

If you know where you're going, look for the command line tools that are part of Mingw included in your Dev-C++ and try to compile it on the command line (my "g++ .... " from before).

that was really helpfull , you solved me the first problem . i had a linker problerm , but i solved it by creating a project and put in there all my files , and delete the code about the main and rewrote it in the new .cpp file . i compiled it and worked fine . thanks a lot .

konefsta
Newbie Poster
9 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
 

Awesome. Glad you got it to work!

jonsca
Quantitative Phrenologist
Team Colleague
5,621 posts since Sep 2009
Reputation Points: 1,165
Solved Threads: 581
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You