|
-
December 18th, 2010, 05:03 AM
#1
new to c++, getting error
Hello, here is my simple program which I am trying to compile and run.
Code:
# include <iostream>
int main()
{
cout << "Hello World" << end1;
int sum = 0;
for(int index = 0; index <= 10; index++)
{
sum += index;
}
cout << "The sum is: " << sum << end1;
return 0;
}
the name of file is firstCPlusPlus.cpp
When I enter 'g++ firstCPlusPlus.cpp into terminal window, get this error:
Undefined symbols:
"_main", referenced from:
start in crt1.10.6.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
Any help would be great. Thinking my code is alright but my compiler side of things is messed. New to the game of c++ and frustrated with this error
Thanks to all for any advice!
Last edited by Marc G; December 18th, 2010 at 10:50 AM.
Reason: Added code tags
-
December 18th, 2010, 10:52 AM
#2
Re: new to c++, getting error
That should work.
However, depending on how old your compiler is, you should get other errors because cout and endl should be prefixed with "std::" or you should put "using namespace std;" at the top of your CPP sourcefile.
Can you tell us the output of:
-
December 19th, 2010, 01:41 AM
#3
Re: new to c++, getting error
Hey Marc,
The output I got from 'g++ --version' is:
i686-apple-darwin10-g++-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5664)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-
December 19th, 2010, 04:11 AM
#4
Re: new to c++, getting error
 Originally Posted by msae
Hey Marc,
The output I got from 'g++ --version' is:
i686-apple-darwin10-g++-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5664)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
That code you posted is not compilable.
Code:
# include <iostream>
int main()
{
cout << "Hello World" << end1;
1) There is no specification of the "std" namespace anywhere in that code.
2) What is end1? Don't you mean endl?
Are you typing your code into the message? If not, don't.
Take the code directly from your code editor, copy it using the copy command, and paste it into the message. Do not type in code, as you see your code has omissions and typographical errors.
Regards,
Paul McKenzie
-
December 21st, 2010, 03:30 AM
#5
Re: new to c++, getting error
you miss the line: using namespace std;
-
December 21st, 2010, 03:54 AM
#6
Re: new to c++, getting error
Hey guys,
I found the problems. Thanks for the tips. It helped a lot. The main issue was that the file was in a different location than the location I was designating when compiling. Had same file names but the one I was compiling had nothing in it. Still do not understand the compile error I got though when nothing there to compile?
Either way, dumb mistake! But thank you for the tips, I fixed other errors along the way!
Ciao till next time,
msae
-
December 21st, 2010, 04:00 AM
#7
Re: new to c++, getting error
Every C/C++ program should have a function called "main" where execution of your application starts. An empty C++ file doesn't have a main function so the linker is complainig about it missing.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|