Thread: Code::Blocks error multiple definition of 'main'

  1. #1
    Registered User
    Join Date
    Jul 2013
    Posts
    4

    Unhappy Code::Blocks error multiple definition of 'main'

    Code::Blocks error multiple definition of 'main'-capture-jpg

    As according to your book Mr. Allain under chapter two i tried to install my first program but it doesnt run. As the default program runs correctly. I created the new file as File>new>empty file and saved as .cpp but the program doesnt run. Ive matched the program from the book and the default one..
    What is wrong...what should i do?

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    What is contained in the main.cpp file? You probably need to remove the Untitled.cpp file from the build.

    Jim

  3. #3
    Registered User
    Join Date
    Jul 2013
    Posts
    4
    The main.cpp file contained a default program the format was same as this one except the string of cout function...after i clicked the red error line the main program got erased..
    What does that mean to remove from build? Sorry ive never used this type of compiler before I've tried c in turboc..

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    What does that mean to remove from build?
    Right now you have to different files being compiled/built to create your program. Both of these files contain a function named main(), you can only have one main. By removing the Untitled.cpp file you will only have one file, main.cpp. If you use this default file and modify it you should be ready to go.

    To remove the file from the build right click on the file name, then select remove file from project. In future when you add files you will probably want to give them a name instead of taking the default name "Untitled.cpp".

    Jim

  5. #5
    Registered User
    Join Date
    Jul 2013
    Posts
    4
    thankyou jim ..the program runs now..
    But how will I create a new program? and compile it without deleting the previous one?.. Also please tell what does this project means..
    Thanks...

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    One project = one program.
    One program consists of many source files that are merged together into one file (executable). A project is a way to keep all these files together and merge them into a single file.
    So, to create a new program, create a new project. That's all.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    Registered User
    Join Date
    Jul 2013
    Posts
    4
    thanks a lot Elysia for clearing my confusion..
    thanx for help..(y)

  8. #8
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Quote Originally Posted by Elysia View Post
    One project = one program.
    One program consists of many source files that are merged together into one file (executable). A project is a way to keep all these files together and merge them into a single file.
    So, to create a new program, create a new project. That's all.
    Technically you could just create a separate CB target for each main function.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multiple Definition error
    By thriller500 in forum C Programming
    Replies: 2
    Last Post: 06-09-2012, 04:02 AM
  2. Multiple definition error, one definition
    By frog in forum C++ Programming
    Replies: 9
    Last Post: 10-21-2010, 03:15 AM
  3. Multiple Definition Error
    By timmeh in forum C++ Programming
    Replies: 9
    Last Post: 02-15-2009, 12:25 PM
  4. Multiple definition Error
    By Esqulax in forum C++ Programming
    Replies: 13
    Last Post: 07-16-2007, 02:44 PM
  5. Multiple definition error
    By gustavosserra in forum C++ Programming
    Replies: 7
    Last Post: 12-11-2003, 08:33 PM