Thursday, August 24, 2017

gcc versus g++

Use gcc for C code
Use g++ for C++ code.
If you have Linux or use Cygwin you will have the GNU Compiler Collection, which provides both gcc and g++.  Traditionally, C programs end in dot c and C++ programs end in dot cc or dot cpp.

Some simple C++ code might compile with gcc, but eventually you will get linker errors like this:
undefined reference to ‘__gxx-personality_v0’
collect2: error: ld returned 1 exit status


If you use g++ and still get this error, try
g++ file.cc -lstdc++
because your compiler is having trouble seeing some C++ Standard Library functions
per
https://stackoverflow.com/questions/6045809/link-error-undefined-reference-to-gxx-personality-v0-and-g

I was glancing at a book on C that mentioned gcc, but did not mention g++, so I thought I should mention this to you if you are starting out as a beginning programmer.

Robert

No comments:

Post a Comment

Comments require my approval before they appear. Be patient. It will take a day or two for your comment to appear.