I recently started learning C++. I am using Visual Studio Code. I get the following error when I press the play button on VSCode and I haven’t found any solutions to the problem on stack overflow that I can understand as my knowledge is limited. If someone knows how to deal with this error, could you please explain why it isn’t building and how to solve it? Thanks so much!!!
Copied the error below (apparently I cannot upload images as I do not have enough reputation):
Starting build…
/usr/bin/gcc -fdiagnostics-color=always -g /home/anthony/CPP/ArrayPractice.cpp -o /home/anthony/CPP/ArrayPractice
/usr/bin/ld: /tmp/cc2tzCtE.o: warning: relocation against _ZSt4cout' in read-only section
.text’
/usr/bin/ld: /tmp/cc2tzCtE.o: in function main': /home/anthony/CPP/ArrayPractice.cpp:11: undefined reference to
std::cout’
/usr/bin/ld: /home/anthony/CPP/ArrayPractice.cpp:11: undefined reference to std::ostream::operator<<(unsigned long)' /usr/bin/ld: /home/anthony/CPP/ArrayPractice.cpp:11: undefined reference to
std::basic_ostream<char, std::char_traits >& std::endl<char, std::char_traits >(std::basic_ostream<char, std::char_traits >&)’
/usr/bin/ld: /home/anthony/CPP/ArrayPractice.cpp:11: undefined reference to std::ostream::operator<<(std::ostream& (*)(std::ostream&))' /usr/bin/ld: /home/anthony/CPP/ArrayPractice.cpp:12: undefined reference to
std::cout’
/usr/bin/ld: /home/anthony/CPP/ArrayPractice.cpp:12: undefined reference to std::ostream::operator<<(int)' /usr/bin/ld: /tmp/cc2tzCtE.o: in function
__static_initialization_and_destruction_0(int, int)’:
/usr/include/c++/11/iostream:74: undefined reference to std::ios_base::Init::Init()' /usr/bin/ld: /usr/include/c++/11/iostream:74: undefined reference to
std::ios_base::Init::~Init()’
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
collect2: error: ld returned 1 exit status
Build finished with error(s).
I am following a course and was expecting an output of 20 in the terminal.
Anthony Song is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.