dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 15

Thread: Please find and correct the error in my c++ program. "Linker Error: Undefined symbol

  1. #1
    Join Date
    Feb 2009
    Posts
    8

    Unhappy Please find and correct the error in my c++ program. "Linker Error: Undefined symbol

    Please find and correct the error in my c++ program. "Linker Error: Undefined symbol _main in module c0.ASM"
    The program is for transfering content of one file to another.

    #include<fstream.h>
    #include<iostream.h>
    #include<conio.h>
    class student
    {
    int rollno;
    char name[20];
    int tm;
    public:
    void input();
    void transfer();
    void output();
    }
    obj;
    void student::input()
    {
    char ch='y';
    ofstream outf;
    outf.open("mark.dat");
    while(ch=='y')
    {
    cout<<"Enter rollno, name and mark";
    cin>>rollno>>name>>tm;
    outf.write((char*)&obj,sizeof(obj));
    cout<<"wish to enter more(Y/N)";
    cin>>ch;
    }
    outf.close();
    }
    void student::transfer()
    {
    ofstream outf;
    ifstream inf;
    inf.open("mark.dat");
    inf.open("trans.dat");
    while(inf)
    {
    inf.read((char*)&obj,sizeof(obj));
    outf.write((char*)&obj,sizeof(obj));
    }
    outf.close();
    inf.close();
    }
    void student:utput()
    {
    ifstream inf;
    inf.open("trans.dat");
    while(inf)
    {
    inf.read((char*)&obj,sizeof(obj));
    cout<<"Rollno"<<rollno;
    cout<<"Name"<<name;
    cout<<"Total"<<tm;
    }
    getch();
    inf.close();
    }

    The error i get is
    compiling 10.cpp
    linking ...\OUTPUT\10.EXE
    .Linker Error: Undefined symbol _main in module c0.ASM

    I think the error is due to the missing of void main. But i don't know where i should put it.

  2. #2
    Join Date
    Feb 2009
    Location
    India
    Posts
    444

    Smile Re: Please find and correct the error in my c++ program. "Linker Error: Undefined sym

    Looks like you haven't defined the main function which is the entry point for the program.
    _Superman_
    I love work. It gives me something to do between weekends.

    Microsoft MVP (Visual C++)

  3. #3
    Join Date
    Feb 2009
    Posts
    8

    Re: Please find and correct the error in my c++ program. "Linker Error: Undefined sym

    Please add main function and correct the program.

  4. #4
    Join Date
    Feb 2009
    Posts
    8

    Re: Please find and correct the error in my c++ program. "Linker Error: Undefined sym

    think i got this from my friend

    void main()
    {
    student obj;
    obj.input();
    obj.transfer();
    obj.output();
    getch();
    }

    He told to put it at last but hwo do i do that?

  5. #5
    Join Date
    Feb 2009
    Posts
    8

    Re: Please find and correct the error in my c++ program. "Linker Error: Undefined sym

    I found the error and corrected it.
    #include<fstream.h>
    #include<iostream.h>
    #include<conio.h>
    class student
    {
    int rollno;
    char name[20];
    int tm;
    public:
    void input();
    void transfer();
    void output();
    }
    obj;
    void student::input()
    {
    char ch='y';
    ofstream outf;
    outf.open("mark.dat");
    while(ch=='y')
    {
    cout<<"Enter rollno, name and mark";
    cin>>rollno>>name>>tm;
    outf.write((char*)&obj,sizeof(obj));
    cout<<"wish to enter more(Y/N)";
    cin>>ch;
    }
    outf.close();
    }
    void student::transfer()
    {
    ofstream outf;
    ifstream inf;
    inf.open("mark.dat");
    inf.open("trans.dat");
    while(inf)
    {
    inf.read((char*)&obj,sizeof(obj));
    outf.write((char*)&obj,sizeof(obj));
    }
    outf.close();
    inf.close();
    }
    void student:utput()
    {
    ifstream inf;
    inf.open("trans.dat");
    while(inf)
    {
    inf.read((char*)&obj,sizeof(obj));
    cout<<"Rollno"<<rollno;
    cout<<"Name"<<name;
    cout<<"Total"<<tm;
    }
    inf.close();
    }
    void main()
    {
    student obj;
    obj.input();
    obj.transfer();
    obj.output();
    getch();
    }

  6. #6
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,649

    Re: Please find and correct the error in my c++ program. "Linker Error: Undefined sym

    And by doing that you've learned a lot more than you had just copying from a forum post.

    By the way, main always returns an int i.e. it should be int main (even though the compiler also accepts the current version)
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    http://www.microsoft.com/visualstudio/eng/downloads

  7. #7
    Join Date
    Feb 2009
    Posts
    8

    Re: Please find and correct the error in my c++ program. "Linker Error: Undefined sym

    I still have another problem. That is when the while loop asks continue(y/n)
    When i enter n it just stuck there.

  8. #8
    Join Date
    Feb 2009
    Posts
    8

    Re: Please find and correct the error in my c++ program. "Linker Error: Undefined sym

    I have corrected almost.

    Please correct the error in my program. When i run the program on turbo c++ 3, it output 3 times. Also When i enter more than 1 entry only the last entry is outputted. Also it is outputted 3 times.

    #include<fstream.h>
    #include<iostream.h>
    #include<conio.h>
    class student
    {
    int rollno;
    char name[20];
    int tm;
    public:
    void input();
    void transfer();
    void output();
    }
    obj;
    void student::input()
    {
    char ch='y';
    ofstream outf;
    outf.open("mark.dat");
    while(ch=='y')
    {
    cout<<"Enter rollno, name and mark";
    cin>>rollno>>name>>tm;
    outf.write((char*)&obj,sizeof(obj));
    cout<<"Wish to enter more(Y/N)?\n";
    cin>>ch;
    }
    outf.close();
    }
    void student::transfer()
    {
    ofstream outf;
    ifstream inf;
    inf.open("mark.dat");
    outf.open("trans.dat");
    while(inf)
    {
    inf.read((char*)&obj,sizeof(obj));
    outf.write((char*)&obj,sizeof(obj));
    }
    outf.close();
    inf.close();
    }
    void student:utput()
    {
    ifstream inf;
    inf.open("trans.dat");
    while(inf)
    {
    inf.read((char*)&obj,sizeof(obj));
    cout<<"\nRollno "<<rollno;
    cout<<"\nName "<<name;
    cout<<"\nTotal "<<tm;
    }
    inf.close();
    }
    void main()
    {
    clrscr();
    student obj;
    obj.input();
    obj.transfer();
    obj.output();
    getch();
    }

  9. #9
    Join Date
    Feb 2009
    Posts
    8

    Re: Please find and correct the error in my c++ program. "Linker Error: Undefined sym

    I have tried to intend it.

    Thank you very much for taking time. I am from India and here we learn about only basics of c++ and our syllabus is based on turbo c++ 3. So i use turbo c++ and i don't know much about c++ programing. So i cannot implement instructions you give on modern c++.

    I tried new changes. But i still have some little problems. The program is to transfer content of one file to another. When i input only one entry, the program works. But when more than one entry is used it out puts only 1 or 2. Kindly please correct the problem.

    Here is the new code by correcting the previous errors.


    Code:
    #include<fstream.h>
    #include<iostream.h>
    #include<conio.h>
    class student
    {
           int rollno;
           char name[20];
           int tm;
           public:
           void input();
           void transfer();
           void output();
     };
    void student::input()
    {
           char ch='y';
           ofstream outf;
           outf.open("mark.dat");
           while(ch=='y')
          {
                   cout<<"Enter rollno, name and mark\n";
                   cin>>rollno>>name>>tm;
                   outf.write((char*)this,sizeof(student));
                   cout<<"Wish to enter more(Y/N)?\n";
                   cin>>ch;
          }
         outf.close();
    }
    void student::transfer()
    {
        ofstream outf;
        ifstream inf;
        inf.open("mark.dat");
        outf.open("trans.dat");
        while( inf.read(( char* )this,sizeof(student))) 
       {
              outf.write(( char* )this,sizeof( student ) );
       }
       outf.close();
       inf.close();
    }
    void student::output()
    {
       ifstream inf;
       inf.open("trans.dat");
       while (inf.read((char*)this, sizeof(student)))
       {
            inf.read(( char* )this,sizeof( student ) );
            cout<<"\nRollno "<<rollno;
            cout<<"\tName "<<name;
            cout<<"\tTotal "<<tm<<'\n';
       }
       inf.close();
    }
    void main()
    {
        clrscr();
        student obj;
        obj.input();
        obj.transfer();
        obj.output();
        getch();
     }

  10. #10
    Join Date
    May 2002
    Location
    Lindenhurst, NY
    Posts
    867

    Re: Please find and correct the error in my c++ program. "Linker Error: Undefined sym

    Quote Originally Posted by tharun518 View Post
    Kindly please correct the problem.
    Generally, when a program does something you don't want or expect, you debug it (as opposed to dumping it on a programming forum). A simple debugging technique is using cout to show the state of variables at various points in your program. Like:
    Code:
    std::cout << "at this point in the program variable x is" << x << std::endl;
    Even better, learn how to use the debugger that comes with your development environment.

  11. #11
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Please find and correct the error in my c++ program. "Linker Error: Undefined sym

    Quote Originally Posted by tharun518 View Post
    I have tried to intend it.

    Thank you very much for taking time. I am from India and here we learn about only basics of c++ and our syllabus is based on turbo c++ 3. So i use turbo c++ and i don't know much about c++ programing. So i cannot implement instructions you give on modern c++.
    "Modern" C++ is over 10 years old. I am surprised you are using something more than 10 years old (closer to 20 years old), especially when there are free C++ compilers (gcc is one of them) that use modern C++ syntax.

    What you're learning now is not what C++ is today or has been for 10 years now, and whoever mandated that this compiler be used is doing you more harm than good. For example, none of those headers (<iostream.h>, <fstream.h>, etc.) exist on many C++ compilers, since they are obsolete.

    Regards,

    Paul McKenzie

  12. #12
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,116

    Re: Please find and correct the error in my c++ program. "Linker Error: Undefined sym

    To add to what Paul just piointed out....

    Many employeers have specific questions in the interview process to locate people who have learned using obsolete tools. These will usually cause the person to be immediately removed from consideration (even for entry level jobs).

    So what you are being taught can actually HURT your career. Find out WHY your professor is teaching material that will do more harm than good. If at all possible switch out of the class or even out of the school.

    Remember it is YOUR future, and YOU have to take responsibility for it.
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  13. #13
    Join Date
    Feb 2009
    Posts
    8

    Re: Please find and correct the error in my c++ program. "Linker Error: Undefined sym

    I got all the program correctly here is it. Our syllabus(school) prescribes this c++. So i am using it.

    Code:
    #include<fstream.h>
    #include<iostream.h>
    #include<conio.h>
    class student
    {
    int rollno;
    char name[20];
    int tm;
    public:
    	void input();
    	void transfer();
    	void output();
    	};
    void student::input()
    {
    char ch='y';
    ofstream outf;
    outf.open("mark.dat");
    while(ch=='y')
    {
    cout<<"Enter rollno, name and mark\n";
    cin>>rollno>>name>>tm;
    outf.write((char*)this,sizeof(student));
    cout<<"Wish to enter more(Y/N)?\n";
    cin>>ch;
    }
    outf.close();
    }
    void student::transfer()
    {
    ofstream outf;
    ifstream inf;
    inf.open("mark.dat");
    outf.open("trans.dat");
    while( inf.read(( char* )this,sizeof(student))) 
    {
    outf.write(( char* )this,sizeof( student ) );
    }
    outf.close();
    inf.close();
    }
    void student::output()
    {
    ifstream inf;
    inf.open("trans.dat");
    while (inf.read((char*)this, sizeof(student)))
    {
    cout<<"\nRollno "<<rollno;
    cout<<"\tName "<<name;
    cout<<"\tTotal "<<tm<<'\n';
    }
    inf.close();
    }
    void main()
    {
    clrscr();
    student obj;
    obj.input();
    obj.transfer();
    obj.output();
    getch();
    }

  14. #14
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Please find and correct the error in my c++ program. "Linker Error: Undefined sym

    Quote Originally Posted by tharun518 View Post
    I got all the program correctly here is it. Our syllabus(school) prescribes this c++. So i am using it.
    Whatever that school is, it should be stripped of its certification to teach C++ programming. At the very least, if you're serious, you should get the free g++ compiler and write the code correctly.

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; February 25th, 2009 at 09:15 PM.

  15. #15
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,116

    Re: Please find and correct the error in my c++ program. "Linker Error: Undefined sym

    Quote Originally Posted by tharun518 View Post
    I got all the program correctly here is it. Our syllabus(school) prescribes this c++. So i am using it.
    Blindly following someone or something once it has been pointed out that it is incorrect (by existing standards) and will be harmful to your future is not a sane decision.

    That is not meant to be "mean" or "rude", but is a simple statement of fact.

    Ask your instructor at the next class session the following question?

    "If I show an assignment to a prospective employeer, that you have given me an A on, and the result is that I am blackballed from the industry; will you (the professor or school) provide me an income for the rest of my life?"

    If the answer is YES, then by all means continue in the current direction. But if either of the following are true, then seriously reconsider the "Value" you are getting from the school...

    a) The professor does not know (or care) that the material that is being taught is WRONG.

    b) The professor knows that it is wrong, but is continuing to teach it, knowing that it will harm your career.

    You position in life is very likely to be influenced for many many years depending on how you handle this.

    Good Luck.
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)