Hello world not working on Unix :(

C

Charles

Hi guys,

I've tried a hello world script:

#include <iostream>

int main() {
using namespace std;

cout << "Hello!\n";
return 0;
}

But I've got an error message:

gcc test.cpp
/var/tmp//ccZLLi7M.o(.text+0xd): In function `std::__verify_grouping(char
const*, unsigned int, std::string const&)':
: undefined reference to `std::string::size() const'
/var/tmp//ccZLLi7M.o(.text+0x60): In function `std::__verify_grouping(char
const*, unsigned int, std::string const&)':
: undefined reference to `std::string::eek:perator[](unsigned int) const'
/var/tmp//ccZLLi7M.o(.text+0x9d): In function `std::__verify_grouping(char
const*, unsigned int, std::string const&)':
: undefined reference to `std::string::eek:perator[](unsigned int) const'
/var/tmp//ccZLLi7M.o(.text+0xc8): In function `std::__verify_grouping(char
const*, unsigned int, std::string const&)':
: undefined reference to `std::string::eek:perator[](unsigned int) const'
/var/tmp//ccZLLi7M.o(.text+0x121): In function `main':
: undefined reference to `std::cout'
/var/tmp//ccZLLi7M.o(.text+0x126): In function `main':
: undefined reference to `std::basic_ostream said:
& std::eek:perator<< <std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&, char const*)'
/var/tmp//ccZLLi7M.o(.text+0x152): In function
`__static_initialization_and_destruction_0(int, int)':
: undefined reference to `std::ios_base::Init::Init()'
/var/tmp//ccZLLi7M.o(.text+0x183): In function `__tcf_0':
: undefined reference to `std::ios_base::Init::~Init()'
/var/tmp//ccZLLi7M.o(.eh_frame+0x11): undefined reference to
`__gxx_personality_v0'

I'm on PC-BSD. Any idea?
Thanks,

Charles.
 
C

Charles

Indeed! It's working fine now.
Thank you Alf!

* Charles:

That's a C++ program. C++ programmers will be _very angry_ if you tell
them
that C++ is a scripting language. You have been Warned. ;-)



Use 'g++' instead of 'gcc'; 'g++' uses 'gcc' internally but in addition
instructs the linker to add necessary C++ libraries, which you're
lacking when
you use 'gcc' directly and not specifying them yourself.

Next time, please ask in a compiler/system-specific group about such
questions, since this group is concerned only with the C++ _language_,
not the
tools (in general).

Cheers,

- Alf
 
A

Alf P. Steinbach

* Charles:
Hi guys,

I've tried a hello world script:

That's a C++ program. C++ programmers will be _very angry_ if you tell them
that C++ is a scripting language. You have been Warned. ;-)

#include <iostream>

int main() {
using namespace std;

cout << "Hello!\n";
return 0;
}

But I've got an error message:

gcc test.cpp

Use 'g++' instead of 'gcc'; 'g++' uses 'gcc' internally but in addition
instructs the linker to add necessary C++ libraries, which you're lacking when
you use 'gcc' directly and not specifying them yourself.

Next time, please ask in a compiler/system-specific group about such
questions, since this group is concerned only with the C++ _language_, not the
tools (in general).

Cheers,

- Alf
 
P

puzzlecracker

Alf -


C++ can be (and at times should be) called scripting language. Lot's
of .bat scripts had, previously, been written by C/C++. Additionally,
scripts written in C++ grammar run faster than any bash or others...


Sometimes it is useful, and perhaps psychologically helpful, to admit
your disgraceful defeat.
 
A

Alf P. Steinbach

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top