How Do You Troubleshoot a C++ Program That Will Not Compile Due to Undefined Reference Errors?

Problem scenario: You try to compile a C++ program with gcc, but you get this output:

/tmp/ccj6eKDl.o: In function `main’:
q.cpp:(.text+0x14): undefined reference to `std::cout’
q.cpp:(.text+0x19): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)’
q.cpp:(.text+0x28): undefined reference to `std::cout’
q.cpp:(.text+0x2d): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)’
/tmp/ccj6eKDl.o: In function `__static_initialization_and_destruction_0(int,

How Do You Compile a C++ Program When You Get “Gcc: Error Trying to Exec ‘cc1plus’: Execvp: No Such File or Directory”?

Problem scenario:  When trying to compile a C++ program (e.g., $ gcc hello.cpp), you receive this error:
“gcc: error trying to exec ‘cc1plus’: execvp: No such file or directory”

What do you do?

Solution
Install gcc-c++.  For a RedHat distribution of Linux, use this command:

yum -y install gcc-c++

How Do You Write a C Program to Writes Hexadecimal Numbers 1 Through F Each on New Lines of a New File?

Problem scenario:  Using the C programming language, you want to write a program that produces a file (we’ll call it contint.txt) that has the following content:

1
2
3
4
5
6
7
8
9
a
b
c
d
e
f

Solution
Overview of the approach:  Hexadecimal numbers use base 16.