If you're working with a makefile and you ended up here like me, then this is probably what you're looking or:
If you're using a makefile, then you need to change cc
as shown below
my_executable : main.o
cc -o my_executable main.o
to
CC = g++
my_executable : main.o
$(CC) -o my_executable main.o