Need Help!!

Hi, I am a rookie coder. Just installed VC++ Express 2010 and wrote to program, "Hello World" and adding two numbers.But I am getting an error message -- fatal error LNK 1169 one or more multiply defined symbols.

Can anybody provide some insight on how to fix it , please ?
post your code
1
2
3
4
5
6
7
8
9
#include<iostream>
int main()
{
	std::cout << "Enter 2 numbers" <<std::endl;
	int n1=0, n2=0;
	std::cin >> n1 >> n2;
	std::cout<< "the sum of n1 and n2 is " << n1+n2 << std::endl;
	return 0;
}

_____

1
2
3
4
5
6
#include<iostream>
int main()
{
	std::cout<< "Hello World"<< std::endl;
	return 0;
}

If you have both of those files in the same project, don't do that.

Make a separate project for each separate program you have.
(Yes, I know, it's tedious, but that's just how MSVC++ works)
Last edited on
both programs are ok
Hey, thanks for the info. There is no other short cut ,other then choosing to create a new project every time ??
Yeah, technically, you'll need a new project for each file.

That's because if you put the files all into one project, the compiler will think that all of those files are somehow related, so it'll try to put all of those files together (kind of) and compile that, which is why you get a "multiple definition" error -- since the compiler (actually, it's the linker) is trying to put together a single program with two different main() functions and getting confused because of it.

What you could do is, instead of making multiple different projects, just make one, and call the file main.cpp or something (doesn't really matter).
When you start working on another program, open up the folder where that main.cpp file is, and copy it to some other place where the program can't see it (and rename it to something more descriptive).
Then, you can overwrite the original main.cpp with your new program.
If you ever want to go back to work on your first program, copy main.cpp to some other place (and rename it appropriately), and then take your first program and copy it back to main.cpp.

Basically, what I'm saying is that whenever you want to work on one of the files, copy it to main.cpp and then open up the project.

You also have the option of using a different IDE that can handle single-file compilation.
I will go with dev-cpp now,i guess.
Anyways, Can you tell me please what is the significance of return statements. In the hello world program (and a couple of other programs), its running fine even without the return 0; line
You're allowed to omit the return 0; from main() only.
(it has the same effect as if you put return 0; at the end)

In all other functions (that don't have a return type of void, of course), you should return a value.
There's some stuff about functions here:
http://www.cplusplus.com/doc/tutorial/functions/
Topic archived. No new replies allowed.