So i recently started programming (C language), and by recently i mean VERY recently. I decided to download Dev-C++ after trying, and failing, to set-up many other C compilers. Well i got it, and i've been reading a book so i decided to copy down another program from it [ already did printf() ] to try it again. Well after finishing it and compiling it, i got the infamous "multiple definitions of 'main'" error.
Specifically:
multiple definitions of 'main'
first defined here
Id returned 1 exit status
And heres it is... I know it's cheesy...
****start program****
#include <stdio.h>
int main()
{
int age;
float weight;
char first[15], last [15];
printf("\nWhat is your first name? ");
scanf(" %s", first);
printf("What is your last name? ");
scanf(" %s", last);
printf("How old are you? ");
scanf(" %d", &age);
printf("How much do you weigh? ");
scanf(" %f", &weight);
printf("\nHere is your information:\n");
printf("Name: %s %s\n", first, last);
printf("Weight: %f\n", weight);
printf("Age: %d\n", age);
return 0;
}
****end program****
So... Yup... Any help would be appreciated.
Dev-C++ help
The linker says you have more than one copy of main in your program. An example might be if you have two different source files which have main() implementations. Or perhaps you have main() in a header file that is included into two source files.
Be aware that Dev-C++ is horrendously out of date, buggy and not maintained. Do yourself a favour and download Visual C++ 2010 Express instead, it is free and is probably the best C++ IDE available for Windows.
Be aware that Dev-C++ is horrendously out of date, buggy and not maintained. Do yourself a favour and download Visual C++ 2010 Express instead, it is free and is probably the best C++ IDE available for Windows.
Do yourself a favour and download Visual C++ 2010 Express instead, it is free and is probably the best C++ IDE available for Windows.
Yes, I highly doing recommend this. If for some reason you don't want to, at least get Code Blocks.
[quote name='rip-off' timestamp='1310557241' post='4834785']
Do yourself a favour and download Visual C++ 2010 Express instead, it is free and is probably the best C++ IDE available for Windows.
Yes, I highly doing recommend this. If for some reason you don't want to, at least get Code Blocks.
[/quote]
Agreed, -or if you find setting up the environment all confusing (so did I when I first started with C++),
just get MingW containing the gcc compilers for windows, and compile from cmd instead.
Of course, you'll be missing out on all the other great features of an IDE, but it will be just you and the concept of learning a language. ;-)
It's very simple: http://www.cs.bu.edu...3/Usingg++.html
Essential reading: http://www.jasonbadams.net/20081218/why-you-shouldnt-use-dev-c/
In Visual Studio, you first need to create a project. Go File -> New -> Project, find and choose Win32 Console Application, choose all of the defaults. It'll create a bunch of files for you, including a <projectname>.cpp. Open that one and write your code in there.
By default, it will also create a precompiled header (stdafx.h and cpp) for you. You can ignore it if you wish, but eventually if your project becomes large, you can put commnly used #includes inside the stdafx.h file which can drastically speed up compile times.
Once you have a project created, the Debug menu will have items like "start debugging" and other useful stuff.
You're free to customize your hotkeys in Tools -> Options -> Environment -> Keyboard.
By default, it will also create a precompiled header (stdafx.h and cpp) for you. You can ignore it if you wish, but eventually if your project becomes large, you can put commnly used #includes inside the stdafx.h file which can drastically speed up compile times.
Once you have a project created, the Debug menu will have items like "start debugging" and other useful stuff.
You're free to customize your hotkeys in Tools -> Options -> Environment -> Keyboard.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement