Answer the question
In order to leave comments, you need to log in
What's wrong with compiling on linux?
I want to learn how to write in C++, but from the very first compilation there are a lot of incomprehensible problems. To the point that I deleted everything and copied Hello World from w3schools . But here are the same problems.
Here is the source:
#include <iostream>
using namespace std;
int main() {
cout << "Hello World!";
return 0;
}
#!/usr/bin/bash
gcc main.cpp -o main
chmod 777 -R ./main
./main
/usr/bin/ld: /tmp/cc4X6rkd.o: in function `main':
main.cpp:(.text+0x12): undefined reference to `std::cout'
/usr/bin/ld: main.cpp:(.text+0x17): 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*)'
/usr/bin/ld: /tmp/cc4X6rkd.o: in function `__static_initialization_and_destruction_0(int, int)':
main.cpp:(.text+0x4b): undefined reference to `std::ios_base::Init::Init()'
/usr/bin/ld: main.cpp:(.text+0x60): undefined reference to `std::ios_base::Init::~Init()'
collect2: error: ld returned 1 exit status
./build.sh: line 4: ./main: No such file or directory
Answer the question
In order to leave comments, you need to log in
You must use g++ or gcc -lstdc++.
But a computer in the window is also a rich idea. =)
PS Also, chmod does not need the -R switch, and 777 is unnecessary, u+x is enough.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question