I\'m trying to compile a simple Hello World program in C++ but I keep getting the following error...why?
gcc -o HelloWorldCompiled HelloWorld.cc
/tmp/ccvLW1e
You have to use g++
, not gcc
. It seems that gcc
understands that it's C++ (so it doesn't give syntax errors), but "forgets" to link it to the C++ standard library.
Try using g++
to compile your C++ code, instead of gcc
, which is used for compiling C programs.
Or you could still use gcc
but explicitly link with the c++ library thusly:
gcc -o HelloWorldCompiled HelloWorld.cc -lstdc++
Use g++
not gcc
. gcc is a C compiler, whereas g++ is a C++ compiler.
g++ -o hwcompiled helloworld.cc
Then to execute your compiled program:
./hwcompiled
Compile with g++
instead of gcc
.