Thread: simple compiling problem

  1. #1
    Waxy-Dock
    Join Date
    Mar 2005
    Posts
    69

    simple compiling problem

    hi everyone,

    im having a problem linking my project..(the classes are very simple)

    it compiles fine..but just wont link...im using ms visual C++..and my classes are

    parser.cpp
    table.cpp
    pguide.cpp (has main)

    as well as some .h files..

    the error message is:
    Linking...
    pguide.obj : error LNK2001: unresolved external symbol "public: __thiscall parser:arser(void)" (??0parser@@QAE@XZ)
    Debug/pguide.exe : fatal error LNK1120: 1 unresolved externals
    Error executing link.exe.

    pguide.exe - 2 error(s), 0 warning(s)

    can someone please help...thanks (the classes are below and .h files are in the attachements)
    ---------
    pguide.cpp
    Code:
    #include "parser.h"
    #include "table.h"
    
    int main(void) {
    	
    	parser p;
    	p.readFile();
    
    	return 0;
    }
    ----------------
    table.cpp
    Code:
    #include "table.h"
    
    table::table(void) {
    
    	cellLength=0;
    	noOfCells=0;
    }
    
    void table::printBar(void) {
    
    }
    -----------
    parser.cpp
    Code:
    #include <fstream>
    #include <string>
    #include "parser.h"
    
    using namespace std;
    
    /* constructor */
    parser::parser(void);
    
    int parser::readFile(void) {
    
    	string filename;
    	string line;
       
    	cout << "File name: ";
    	cin >> filename;
       
    	ifstream file(filename.c_str());
       
    	if(!file.is_open()) {
    
    		cout << "Error...file is not opened" << endl;
            return 0;
    	} 
    	
    	else
    		return 1;
    	
    
    	while (!file.eof()) {
    
    		getline(file, line);
    		cout << line << endl;
    	}
    
    	file.close();
    }

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    I think it has something to do with this:
    Code:
    int main(void) {
    	
    	parser p;
    and
    Code:
    /* constructor */
    parser::parser(void);
    You haven't defined your constructor which was called by the line:

    parser p;

    Also, eliminate 'void' in the main header:

    Code:
    int main()
    {
    
        //your code here
    
        return 0;
    }

  3. #3
    Registered User
    Join Date
    Mar 2004
    Posts
    536
    Quote Originally Posted by waxydock
    hi everyone,

    im having a problem linking my project..(the classes are very simple)

    it compiles fine..but just wont link...im using ms visual C++..and my classes are

    parser.cpp
    table.cpp
    pguide.cpp (has main)

    as well as some .h files..

    the error message is:
    Linking...
    pguide.obj : error LNK2001: unresolved external symbol "public: __thiscall parser:arser(void)" (??0parser@@QAE@XZ)
    Debug/pguide.exe : fatal error LNK1120: 1 unresolved externals
    Error executing link.exe.

    pguide.exe - 2 error(s), 0 warning(s)

    can someone please help...thanks (the classes are below and .h files are in the attachements)
    ---------
    you declared a constructor in parser.h:

    Code:
    public:
    
    	parser(void);
    But you never defined the function. In parser.cpp, change this

    Code:
    parser::parser(void);
    to this:

    Code:
    parser::parser(void)
    {
    }
    (Then, later when everything compiles OK, you can implement some functionality in the constructor.)

    Regards,

    Dave

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with simple C programming
    By YAV in forum C Programming
    Replies: 2
    Last Post: 11-17-2008, 10:29 AM
  2. gcc compiling and linking problem
    By maven in forum C Programming
    Replies: 6
    Last Post: 11-14-2008, 05:28 AM
  3. Problem with simple XOR program
    By spike_ in forum C++ Programming
    Replies: 8
    Last Post: 08-17-2005, 12:09 AM
  4. problem with A simple modeless messagebox
    By hanhao in forum C++ Programming
    Replies: 8
    Last Post: 07-05-2005, 11:18 PM
  5. Replies: 5
    Last Post: 12-03-2003, 05:47 PM