简体   繁体   中英

Can't find c++ libraries on unix

I've written a simple c++ program, test.cpp:

#include <iostream>
#include <string>

using namespace std;

int main() {
  string s;
  cin >> s;
  cout << s << endl;
  return 0;
}

Why does runnning gcc test.cpp -o mytest give me these errors, and more?

Undefined symbols for architecture x86_64:
  "std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string()", referenced from:
      _main in cc8rGYVq.o
  "std::cin", referenced from:
      _main in cc8rGYVq.o

Don't use the executable named gcc to compile and link C++ programs; you must use g++ . Not only does it select the appropriate compiler options, it also links with the right libraries for your language (which is the problem you're having here.)

“ gcc”命令编译C代码,为了编译C ++代码,您应该使用“ g ++”

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM