Compiling Errors

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2009
Posts: 8
Reputation: konefsta is an unknown quantity at this point 
Solved Threads: 0
konefsta konefsta is offline Offline
Newbie Poster

Compiling Errors

 
0
  #1
Nov 7th, 2009
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
  1.  
  2. #include "Ergasia1.h"
  3. #include "Feature.h"
  4.  
  5. using namespace std;
  6.  
  7. Ergasia1::Ergasia1()
  8. {
  9. #ifdef DEVEL
  10. tst= "../../";
  11. #else
  12. tst= "./";
  13. #endif
  14.  
  15. bool AllOK= FillvsKeys();
  16. if (AllOK) {
  17. GetFiles(LING);
  18. GetFiles(SPAM);
  19. ShowData();
  20. }
  21. else
  22. cout << "Incorrect Installation!" << endl;
  23. }
  24.  
  25. const void Ergasia1::AnalyzeFile(const string fn) {
  26. string fname= fn.substr(tst.length());
  27. size_t pos= fname.find_first_of("/");
  28. string kind= "";
  29. if (pos != string::npos)
  30. kind= fname.substr(0, pos);
  31. int KeywordsFound= 0;
  32. ifstream ifs(fn.c_str());
  33. if (ifs.is_open()) {
  34. n++;
  35. vector<Feature> vf;
  36.  
  37. while (! ifs.eof()) {
  38. string line;
  39. getline(ifs, line);
  40.  
  41. for (unsigned int i= 0; i < vsKeys.size(); i++) {
  42. string key= vsKeys[i];
  43. if (line.find(key) != string::npos) {
  44. bool found= false;
  45. for (unsigned int j= 0; j < vf.size(); j++)
  46. if (vf[j].getDescription().compare(key) == 0) {
  47.  
  48. int x= vf[j].getFrequency();
  49. vf[j].setFrequency(++x);
  50. found= true;
  51. break;
  52. }
  53. if (! found) {
  54.  
  55. Feature *f= new Feature(i, 1, key);
  56. vf.push_back(*f);
  57. KeywordsFound++;
  58. }
  59. }
  60. }
  61. }
  62. ifs.close();
  63. ostringstream osst;
  64. osst << "<message file=\"" << fname <<"\" category=\"" << kind << "\" features=\"" << KeywordsFound << "\">";
  65. vsStream.push_back(osst.str());
  66. osst.flush();
  67. for (unsigned int i= 0; i < vf.size(); i++) {
  68. ostringstream ossb;
  69. ossb << "<feature id=\"" << vf[i].getId() << "\" freq=\"" << vf[i].getFrequency() << "\"> " << vf[i].getDescription() << " </feature>";
  70. vsStream.push_back(ossb.str());
  71. ossb.flush();
  72. }
  73. ostringstream osse;
  74. osse << "</message>";
  75. osse.flush();
  76.  
  77. }
  78. }
  79.  
  80. const void Ergasia1::GetFiles(const string Kind) {
  81. string s= tst + Kind + FILENAME;//"_filenames.txt";
  82. ifstream ifs(s.c_str());
  83. if (ifs.is_open()) {
  84. while (! ifs.eof()) {
  85. string line;
  86. getline(ifs, line);
  87. AnalyzeFile(tst + line);
  88. }
  89. ifs.close();
  90. }
  91. }
  92.  
  93. const bool Ergasia1::FillvsKeys() {
  94. bool result= true;
  95. string s= tst + KEYWORDS;
  96. n= 0;
  97. ifstream ifs(s.c_str());
  98. if (ifs.is_open()) {
  99. while (! ifs.eof()) {
  100. string line;
  101. getline(ifs, line);
  102. vsKeys.push_back(line);
  103. }
  104. }
  105. else
  106. result= false;
  107. ifs.close();
  108. return result;
  109. }
  110.  
  111. const void Ergasia1::ShowData() {
  112. cout << "<messagecollection messages=\"" << n << "\">" << endl;
  113. for(unsigned int i= 0; i < vsStream.size(); i++)
  114. cout << vsStream[i] << endl;
  115. cout << "</messagecollection>" << endl;
  116. }
  117.  
  118. int main(int argc, char **argv) {
  119. Ergasia1 e;
  120. return 0;
  121. }



Ergasia.h
  1. #include <fstream>
  2. #include <string>
  3. #include <vector>
  4. #include <iostream>
  5. #include <sstream>
  6.  
  7. #ifdef _DEBUG
  8. #define DEVEL
  9. #endif
  10.  
  11. using namespace std;
  12.  
  13. #ifndef FILENAME
  14. #define FILENAME "_filenames.txt";
  15. #endif
  16.  
  17. #ifndef KEYWORDS
  18. #define KEYWORDS "keywords.txt"
  19. #endif
  20.  
  21. #ifndef LING
  22. #define LING "ling"
  23. #endif
  24.  
  25. #ifndef SPAM
  26. #define SPAM "spam"
  27. #endif
  28.  
  29. #ifndef ERGASIA1_H
  30. #define ERGASIA1_H
  31.  
  32. class Ergasia1
  33. {
  34. private:
  35. int n;
  36. string tst;
  37. //static const string FileName;
  38. vector<string> vsKeys;
  39. vector<string> vsStream;
  40. const void AnalyzeFile(const string fn);
  41. const void GetFiles(const string Kind);
  42. const bool FillvsKeys();
  43. const void ShowData();
  44.  
  45. public:
  46. Ergasia1();
  47. }
  48. #endif
  49. //ERGASIA1_H
  50.  
  51. int main(int argc, char **argv);


Feature.cpp
  1. #include "Feature.h"
  2.  
  3. void Feature::setId(int i) {
  4. Id= i;
  5. }
  6.  
  7. void Feature::setFrequency(int f) {
  8. Frequency= f;
  9. }
  10.  
  11. void Feature::setDescription(const string d) {
  12. Description= d;
  13. }
  14.  
  15. int Feature::getId() {
  16. return Id;
  17. }
  18.  
  19. int Feature::getFrequency() {
  20. return Frequency;
  21. }
  22.  
  23. string Feature::getDescription() {
  24. return Description;
  25. }
  26.  
  27. Feature::Feature(int i, int f, const string d) {
  28. setId(i);
  29. setFrequency(f);
  30. setDescription(d);
  31. }




Feature.h
  1. #include <iostream>
  2. using namespace std;
  3. #ifndef FEATURE_H
  4. #define FEATURE_H
  5.  
  6. class Feature {
  7. private:
  8. int Id;
  9. int Frequency;
  10. string Description;
  11. public:
  12. void setId(int i);
  13. void setFrequency(int f);
  14. void setDescription(const string d);
  15. int getId();
  16. int getFrequency();
  17. string getDescription();
  18. Feature(int i, int f, const string d);
  19. }
  20. #endif
  21. //FEATURE_H


thats the files i created . any help will be appreciate . thanks in advance my friends .
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 481
Reputation: Clinton Portis is on a distinguished road 
Solved Threads: 58
Clinton Portis's Avatar
Clinton Portis Clinton Portis is offline Offline
Posting Pro in Training
 
0
  #2
Nov 7th, 2009
Just looking briefly, I see one error on line #14 of ergasia.h:
#define FILENAME "_filenames.txt";
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 8
Reputation: konefsta is an unknown quantity at this point 
Solved Threads: 0
konefsta konefsta is offline Offline
Newbie Poster
 
0
  #3
Nov 7th, 2009
i still have the same errors .
any other ideas ?
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 608
Reputation: jonsca is on a distinguished road 
Solved Threads: 80
jonsca jonsca is offline Offline
Practically a Master Poster
 
0
  #4
Nov 7th, 2009
Seem to be missing semicolons after your class declarations in the headers:
  1. class Feature {
  2. private:
  3. int Id;
  4. int Frequency;
  5. string Description;
  6. public:
  7. void setId(int i);
  8. void setFrequency(int f);
  9. void setDescription(const string d);
  10. int getId();
  11. int getFrequency();
  12. string getDescription();
  13. Feature(int i, int f, const string d);
  14. }; <-------------- (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.
Last edited by jonsca; Nov 7th, 2009 at 12:32 pm.
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 8
Reputation: konefsta is an unknown quantity at this point 
Solved Threads: 0
konefsta konefsta is offline Offline
Newbie Poster
 
0
  #5
Nov 7th, 2009
i still have the same errors
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 8
Reputation: konefsta is an unknown quantity at this point 
Solved Threads: 0
konefsta konefsta is offline Offline
Newbie Poster
 
0
  #6
Nov 7th, 2009
i am thinking , is it possible that i am missing a file or something ?
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 608
Reputation: jonsca is on a distinguished road 
Solved Threads: 80
jonsca jonsca is offline Offline
Practically a Master Poster
 
0
  #7
Nov 7th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 8
Reputation: konefsta is an unknown quantity at this point 
Solved Threads: 0
konefsta konefsta is offline Offline
Newbie Poster
 
0
  #8
Nov 8th, 2009
how can i compile them in the same time ? i am using Dev-C++ and wxDev-C++
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 8
Reputation: konefsta is an unknown quantity at this point 
Solved Threads: 0
konefsta konefsta is offline Offline
Newbie Poster
 
0
  #9
Nov 8th, 2009
?
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 608
Reputation: jonsca is on a distinguished road 
Solved Threads: 80
jonsca jonsca is offline Offline
Practically a Master Poster
 
0
  #10
Nov 8th, 2009
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/Insta...ng_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.
Reply With Quote Quick reply to this message  
Reply

Message:




Views: 337 | Replies: 13
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC