I'm working on a small openGl program (just a test actually), and need to use standard output (cout) to debug my program. I included iostream (#include <iostream>), and am using namespace std; I'm compiling with:
gcc -o cube main.cpp -lGL -lGLU -lglut
but it's giving me this error:
undefined reference to symbol '_ZNSt8ios_base4InitD1Ev@@GLIBCXX_3.4'
//usr/lib/x86_64-linux-gnu/libstdc++.so.6: error adding symbols: DSO missing from command line
I have build-essential installed, so there shouldn't be a problem linking to iostream.
You have two different sets of compiler flags enabled :P
Anyways, AFAIK gcc invokes g++ for c++ files as it is just a collection of compilers. Code::blocks uses gcc. You could also use the gcc compiler flag -lstdc++ to tell it that it is a c++ file.
> Use g++ and not gcc - the latter is for C, the former for both C and C++.
1 2 3
int main(){
intclass = 42;
}
$ gcc bar.c
$ echo $?
0
$ g++ bar.c
bar.c: In function ‘int main()’:
bar.c:2:2: error: expected primary-expression before ‘int’
man gcc wrote:
Options Controlling the Kind of Output
Compilation can involve up to four stages: preprocessing, compilation proper,
assembly and linking, always in that order. (...)
For any given input file, the file name suffix determines what kind of
compilation is done:
I suppose that the last paragraph refer to compilation proper
You may use the `gcc' command for compiling c++ source code.
Edit: here it is
Compiling C++ Programs
C++ source files conventionally use one of the suffixes .C, .cc, .cpp, .CPP,
.c++, .cp, or .cxx; C++ header files often use .hh, .hpp, .H, or (for shared
template code) .tcc; and preprocessed C++ files use the suffix .ii. GCC
recognizes files with these names and compiles them as C++ programs even if you
call the compiler the same way as for compiling C programs (usually with the
name gcc).
However, the use of gcc does not add the C++ library. g++ is a program that
calls GCC and automatically specifies linking against the C++ library.
$ make
g++ -c -o main.o main.cpp
gcc -o prog main.o
main.o: In function `main':
main.cpp:(.text+0xa): undefined reference to `std::cout'
Gcc is good at knowing to use g++ for a c++ source file, but it defaults to cc to link the objects. ( or maybe it is make that knows the difference, but at least I get credit for recreating the problem :) )
I was responding at LB claim of using g++ for C code
> Gcc is good at knowing to use g++ for a c++ source file, but it defaults to cc to link the objects.
> ( or maybe it is make that knows the difference
¿why did I ever bother to post the man pages?
Edit: Your makefile is using an implicit rule for compilation