compiling problem

This is a discussion on compiling problem within the C++ Programming forums, part of the General Programming Boards category; i have Borland compiler version 5.51 for Win 32 when i try to compile this script: #include <iostream.h> int number_of_doritos(void) ...

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    6

    compiling problem

    i have Borland compiler version 5.51 for Win 32
    when i try to compile this script:
    #include <iostream.h>

    int number_of_doritos(void)
    {
    int yum;

    yum = 523; /* That's a lot of doritos! */

    return yum; /* Returns the value in yum, stops the function */

    cout << "I hate doritos!" << endl; /* Nobody ever sees this */
    return yum;

    }

    theres an error: Unresolved external '_main' refrenced from D:\BORLAND\BCC55\LIB\COX.OBJ

    i have no idea what to do

    (i copied the bin folder of borland in a diff dirrectory for easy compiling i wonder if it has to be with the other folders lib, examples, include, help )

    any help?

  2. #2
    Fingerstyle Guitarist taylorguitarman's Avatar
    Join Date
    Aug 2001
    Posts
    564
    There's no main that's what the error is telling you. Or it's having a problem finding it.
    Are you merely compiling or are you trying to build?

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    6
    whats the diff ?
    lol sry i am new at this i jsut followed a tutorial and i pasted the code and saved it in .cpp and i want to comile it plz help me

  4. #4
    _B-L-U-E_ Betazep's Avatar
    Join Date
    Aug 2001
    Posts
    1,412
    Yep... no main.


    Just curious though, why do you have two return statements in your function if you know that the latter one will never be reached?
    Blue

  5. #5
    _B-L-U-E_ Betazep's Avatar
    Join Date
    Aug 2001
    Posts
    1,412
    Do you have a 'main' function anywhere?

    Like

    int main()
    {

    ...

    return 0;
    }

    or

    void main()
    {

    }

    etc etc.... anything with main. If main is in a seperate file then, you compile each file into an object file without the linking. The reason why you were asked if you are building or compiling is that your error happens when the linker cannot find main.

    main is very important in C++. Without it... you do not have an executable program (well sort of).

    Is there more to your program than this?
    Blue

  6. #6
    Fingerstyle Guitarist taylorguitarman's Avatar
    Join Date
    Aug 2001
    Posts
    564
    Compiling a program checks the syntax of the program and makes an object file.
    Building on the other hand links all of the parts of the program together to make an executable file.
    Therefore you compile parts of the program, such as libraries but you build the main program. That's when you need an entry point. ( the main() )
    Are you using the command line version or the IDE?

  7. #7
    Registered User
    Join Date
    Dec 2001
    Posts
    6
    hmmmm itnt the
    int number_of_doritos(void)
    the main?
    hmmmmm maybe an example would help alot if you have a simple code to show me how to do this please (or a tutorial site)
    thanx for all of your help ill get it someday lol

  8. #8
    Still A Registered User DISGUISED's Avatar
    Join Date
    Aug 2001
    Posts
    499
    hmmmm itnt the
    int number_of_doritos(void)
    the main?
    All C/++ programs are built in or around a function called Main. This is the heart ..or "Driver" of the program. This is really one of the first basic concepts that we were taught in school. I am still learning myself. I suggest that you get a good book if you are really interested in learning to program. Most online tutorials are just very general ..but good references all the same.

    Start here to learn more about the language itself, and to find some good books. Then you can advance at your own pace from there.

  9. #9
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    All C/++ programs are built in or around a function called Main. This is the heart ..or "Driver" of the program. This is really one of the first basic concepts that we were taught in school.
    Close but not right. C++ is CASE-SENSITIVE. Main() is wrong. It has to be main() for a console mode program and WinMain() for windows programs.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  10. #10
    wierd guy bart's Avatar
    Join Date
    Aug 2001
    Posts
    87

  11. #11
    Denethor2000
    Guest
    int main()
    {
    int yum;

    yum = 523; /* That's a lot of doritos! */

    cout << "I hate doritos!" << endl; /* Nobody ever sees this */
    return yum;

    }



    try this

  12. #12
    Registered User
    Join Date
    Dec 2001
    Posts
    6
    Denethor when i type in ur code this is what i get:
    Error E2451 doritos.cpp 7: Undefined symbol 'cout' in function main()
    Error E2451 doritos.cpp 7: Undefined symbol 'endl' in function main()
    *** 2 errors in Compile ***

  13. #13
    Registered User
    Join Date
    Dec 2001
    Posts
    32
    You need to add

    #include <iostream>
    using namespace std;

    at the top, for cout and endl to be recognized.

    Seron

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem Running Program After Compiling
    By kristentx in forum C++ Programming
    Replies: 13
    Last Post: 09-12-2007, 11:46 AM
  2. Problem compiling simple code examples
    By Wintersun in forum Windows Programming
    Replies: 8
    Last Post: 08-14-2007, 11:30 AM
  3. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 03:51 PM
  4. compiling problem
    By tinkerbell20 in forum C++ Programming
    Replies: 6
    Last Post: 06-21-2005, 01:12 PM
  5. simple compiling problem
    By waxydock in forum C++ Programming
    Replies: 2
    Last Post: 03-26-2005, 10:33 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21