collect2: error: ld returned 1 exit status in c++ -
this question has answer here:
- compiling c++ program gcc 7 answers
i have switched elementary os , installed sublime text editor. wrote basic hello world program in c++ check working. , error.
/tmp/cc3pmvft.o: in function `main': source.cpp:(.text+0xa): undefined reference `std::cout' source.cpp:(.text+0xf): undefined reference `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)' source.cpp:(.text+0x14): undefined reference `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)' source.cpp:(.text+0x1c): undefined reference `std::ostream::operator<<(std::ostream& (*)(std::ostream&))' /tmp/cc3pmvft.o: in function `__static_initialization_and_destruction_0(int, int)': source.cpp:(.text+0x4a): undefined reference `std::ios_base::init::init()' source.cpp:(.text+0x59): undefined reference `std::ios_base::init::~init()' collect2: error: ld returned 1 exit status
the hello world program was,
#include <iostream> using namespace std; int main(){ cout << "hello world!" << endl; return 0; }
i have searched answer in google , stackoverflow couldn't find solution.
you should compile c++ compiler, not c, g++ example.
instead of
gcc source.cpp
do this
g++ source.cpp
Comments
Post a Comment