I was coding a very simply program which is basically hello world:
#include <string>
#include <vector>
int main() {
std::vector<std::string> vec = {"Hello", "World"};
for (const auto &num : vec) {
std::cout << num << std::endl;
}
return 0;
}
Then I use a shell command to compile and execute the file:
echo "Start compling: "
g++ -std=c++11 -Werror -o test test.cpp
echo "File complied!"
echo "Start excuting: "
./test
echo "Program stopped"
In this way, everything is fine. But if I change the second command into:
g++ -std=c++11 -o -Werror test test.cpp
The compiler gives me such warnings ( which I treat as errors ) :
Start compling:
/usr/bin/ld: test: _ZSt4cout: invalid version 2 (max 0)
/usr/bin/ld: test: error adding symbols: bad value
collect2: error: ld returned 1 exit status
File complied!
Start excuting:
Hello
World
Program stopped
I really can't figure out why the order of the parameters would cause this.