Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2016
    Posts
    9
    Rep Power
    0

    Linker Error : Undefined symbol _main in module c0.ASM


    Code:
    #include<iostream.h>
    #include<conio.h>
    #include<iomanip.h>
    #include<fstream.h>
    #include<graphics.h>
    #include<dos.h>
    #include<string.h>
    #include<stdio.h>
    #include <time.h>
    fstream inoutfile;
    int main();
    //Menu Global Item
    
    #define pixTOrc(x) (8*(x-1))  //convert pixel into row and col format
    #define INC 5  //Increment Distance Between Menu Items
    #define ROW 15 //Row Value for Menu Item
    #define COL 8 //Column Value for Menu Item
    
    // To display the Inventory Main menu options
    typedef char option[15];
    option mainMenu[]= {
      "New Record",
      "Display",
     "Search",
     "Updation",
     "Deletion",
     "Analysis",
     "Exit"
    };
    
    
    
    
    
    
    
    /*-------------------Inventory Class--------------------*/
    
    class Inventory{
    		 char itemNo[2],itemName[20];
    		 int qty;
    		 double price,amt;
    
    		 public:
    
    		 char *getno(){return itemNo;}
    		 char *getitem(){ return itemName;}
    		 double getamt(){return amt;}
    		 void getdata();
    		 void showdata(int,int);
    		 void showspecific();
    		 void alterspecific(char *,char *);
    };
    
    void Inventory :: getdata(){
    		 gotoxy(30,12);
    		 cout<<"Enter Item Number : ?";
    		 cin>>itemNo;
    		 gotoxy(30,14);
    		 cout<<"Enter Item Name : ?";
    		 cin>>itemName;
    		 gotoxy(30,16);
    		 cout<<"Enter Quantity : ?";
    		 cin>>qty;
    		 gotoxy(30,18);
    		 cout<<"Enter Price : ?";
    		 cin>>price;
    		 amt = price * qty;
    }
    
    void Inventory :: showdata(int x,int y){
    		 gotoxy(x,y);
    		 cout.setf(ios::left,ios::adjustfield);
    		 cout<<setw(3)<<itemNo;
    		 cout.setf(ios::left,ios::adjustfield);
    		 cout<<setw(13)<<itemName;
    		 cout<<setw(4)<<qty;
    		 cout.setf(ios::right,ios::adjustfield);
    		 cout.setf(ios::showpoint);
    		 cout.setf(ios::fixed,ios::floatfield);
    		 cout<<setprecision(2)<<setw(8)<<price;
    		 cout.setf(ios::right,ios::adjustfield);
    		 cout.setf(ios::showpoint);
    		 cout.setf(ios::fixed,ios::floatfield);
    		 cout<<setprecision(2)<<setw(15)<<amt;
    }
    
    void Inventory :: showspecific(){
    		 gotoxy(30,13);
    		 cout<<"--Search Item Found--";
    		 gotoxy(30,15);
    		 cout<<"Item No : ";
    		 cout.setf(ios::left,ios::adjustfield);
    		 cout<<itemNo;
    		 gotoxy(30,17);
    		 cout<<"Item Name : ";
    		 cout.setf(ios::left,ios::adjustfield);
    		 cout<<itemName;
    		 gotoxy(30,19);
    		 cout<<"Quantity : ";
    		 cout<<qty;
    		 cout.setf(ios::right,ios::adjustfield);
    		 cout.setf(ios::showpoint);
    		 cout.setf(ios::fixed,ios::floatfield);
    		 gotoxy(30,21);
    		 cout<<"Price : ";
    		 cout<<setprecision(2)<<price;
    		 gotoxy(30,23);
    		 cout<<"Amount : ";
    		 cout.setf(ios::right,ios::adjustfield);
    		 cout.setf(ios::showpoint);
    		 cout.setf(ios::fixed,ios::floatfield);
    		 cout<<setprecision(2)<<amt;
    }
    
    void Inventory :: alterspecific(char itmno[2],char itmname[20]){
    		 strcpy(itemNo,itmno);
    		 strcpy(itemName,itmname);
    		 gotoxy(30,16);
    		 cout<<"Enter Quantity : ?";
    		 cin>>qty;
    		 gotoxy(30,18);
    		 cout<<"Enter Price : ?";
    		 cin>>price;
    		 amt = price * qty;
    }
    Please help.
  2. #2
  3. Not An Expert
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2015
    Posts
    404
    Rep Power
    3
    Hello and welcome,

    In the future, please place your code between [code] tags to preserve the formatting and spacing of the code. You can also use [PHP] tags if posting PHP for highlighting.

    Also, I think our users will need more information. What do you need help with? What's wrong with the code? Are there any errors being thrown? More information, in general, is required.

    Thank you!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2016
    Posts
    9
    Rep Power
    0
    I am getting error
    Linker Error : Undefined symbol _main in module c0.ASM
  6. #4
  7. Not An Expert
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2015
    Posts
    404
    Rep Power
    3
    Ah - I guess I should have recognized that from the thread title. My mistake, I apologize.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2016
    Posts
    9
    Rep Power
    0
    No problem.Did you find the solution yet?
  10. #6
  11. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,782
    Rep Power
    4301
    Yes, you have this line in your code:
    Code:
    #include <time.h>
    fstream inoutfile;
    int main(); // <------------- Why are you declaring a prototype for main here and where did you write the main() function code.
    //Menu Global Item
    You need to make a main() function somewhere in your code. What you've done is declare a prototype, but no actual function.

    As a side note, please stop using Turbo C++ to learn how to program in C++. That compiler is seriously outdated, targets a long obsolete OS and doesn't follow the current C++ standards. You should try using a more recent compiler such as gcc, Visual C++ etc. (which are both free, much more recent and are better at following standards). Also, if you're following a book by a guy called Kanetkar, be warned that the author doesn't know what he's talking about and shouldn't be programming, much less teaching.
    Last edited by Scorpions4ever; July 14th, 2016 at 04:56 PM.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2016
    Posts
    9
    Rep Power
    0
    Firstly i didn't declare a main() function so it shows a same error then i try to find the solution it says you have error in main() function,so i declared it.Can you pls tell me where to declare it.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2014
    Location
    India
    Posts
    200
    Rep Power
    4
    Originally Posted by Shubhang Agarwa
    Firstly i didn't declare a main() function so it shows a same error then i try to find the solution it says you have error in main() function,so i declared it.Can you pls tell me where to declare it.
    What Scorpions4ever means is that you've only declared the function-prototype of your main() function. You have to define it somewhere. And I don't understand the need to declare a function-prototype for the main function. Afaik, function-prototypes should only be declared for the functions you'll be using later in your program but the main function isn't used by you, it's used by whatever executes your program.

    Can you pls tell me where to declare it.
    Anywhere, as you would do with any other function outside of a class, it's mostly a personal preference. In most examples of code you would find it declared before other functions (see src/bin/ls/ls.c - view - 1.67).

    Although due to the platform-dependent assumptions in your code I'm not able to compile it but try declaring the main function. If any other errors are there you can surely reply back here.
    Last edited by hexman; July 15th, 2016 at 09:54 AM.
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2016
    Posts
    9
    Rep Power
    0
    just help run my program
  18. #10
  19. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,782
    Rep Power
    4301
    Your main() function should look something like this:
    Code:
    int main(void) {
       Inventory inv;
       cout << "Hello world\n";
       // Do things with inv here
       return 0;
    }
    Seriously though, have you ever written any kind of C or C++ program before?? I'm trying to gauge your level of experience here, because the first thing they usually teach in most courses is how to write the main() function.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  20. #11
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2016
    Posts
    9
    Rep Power
    0
    Tried everything but couldn't run my program.
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2016
    Location
    S.E. Washington state
    Posts
    11
    Rep Power
    0
    Originally Posted by Shubhang Agarwa
    Tried everything but couldn't run my program.
    If you are coding in C or C++ your program has to "run" through the main function.
    Code:
    #include <headerfiles.h>
    function declarations;
    int main(void) // main begins here
    {
        your instructions to run your program here;
        your calls to child functions;
    } return(0);  // main ends here
    Functions of the program here
    Your main function has no instructions in it to run the program.
  24. #13
  25. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2016
    Posts
    9
    Rep Power
    0
    Its still not running.
  26. #14
  27. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,782
    Rep Power
    4301
    Try this in a separate file by itself:
    Code:
    #include <iostream.h>
    int main(void) {
        cout << "Hello world\n";
        return 0;
    }
    If you can get that to run, then we're getting somewhere and can go on from there. If you can't, then the installation of your compiler is wrong and ask your professor for help.
    // Yes, I know that code is non-conformant by recent C++ standards, but the original poster is using a non-conformant obsolete C++ compiler.

    Comments on this post

    • b49P23TIvg agrees : Superior debugging!
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  28. #15
  29. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2016
    Posts
    9
    Rep Power
    0
    You are right,i can't run your simple program.
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo