在 unix 上找不到 C++ 库 [英] Can't find c++ libraries on unix

查看:33
本文介绍了在 unix 上找不到 C++ 库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个简单的 C++ 程序 test.cpp:

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;
}

为什么运行 gcc test.cpp -o mytest 会给我这些错误,以及更多?

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

推荐答案

不要使用名为 gcc 的可执行文件来编译和链接 C++ 程序;你必须使用 g++.它不仅会选择适当的编译器选项,还会链接到适合您语言的库(这是您在这里遇到的问题.)

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.)

这篇关于在 unix 上找不到 C++ 库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆