Compiling a simple C++ code

Hi All,

I am trying to compile a C++ code and it gives me the below error.

/usr/ccs/bin/ld: Unexpected end of file in test.cpp

The code test.cpp just prints "Hello World"

Can you please help me to compile this code successfully.

Thanks in advance.

Regards,
Poornima.
Poornima,

Can you paste your code here?
I'm betting on a missing closing brace }
#include <iostream>
using namespace std;

int main ()
{
cout << "Hello World!";
return 0;
}

The above is the code..
0 errors, 0 warnings
What compiler are you using?
What compiler are you using?

I want to point out the redundancy of this question by quoting Poornina:

/usr/ccs/bin/ld: Unexpected end of file in test.cpp
Last edited on
I am using cc compiler.
A shot in the dark - why is it that ld is reporting an error in a cpp file.
Isn't ld the linker??
any inputs?
code seems to work fine, copied, pasted, compiled and run. Just outputs the message, by the way you don't actually need the namespace for your program as your only using cout anyway.
even removing the line "using namespace std" my code produces the same error..
All I can think is that the file contains a premature EOF which your editor doesn't display.
Why don't you upload it or post it as base64?
While you're at it, post the command you're using to compile.
cc test.cpp is the command I was using to compile the file.
Something tells me that that's a C compiler (although I tried compiling a C++ source with gcc and got a different error message).
How about g++ test.cpp?
You are using Linux, right? Or maybe BSD?
I am using Unix..
Topic archived. No new replies allowed.