如何在 Linux ubuntu 中设置 C++ 环境变量?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3040750/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 11:53:07  来源:igfitidea点击:

How to set C++ environment variable in Linux ubuntu?

c++linuxenvironment-variables

提问by HaggarTheHorrible

I just installed Ubuntu on my Virtualbox on Windows.

我刚刚在 Windows 上的 Virtualbox 上安装了 Ubuntu。

I was trying to install cmake and the installation guide in the cmake website asked me to do the following steps

我正在尝试安装 cmake 并且 cmake 网站中的安装指南要求我执行以下步骤

./bootstrap
make
make install

But when I just did the ./bootstrapcommand I get the following list of errors, can anyone suggest me how I can set the C++ compiler on my system. As I just installed Ubuntu perhaps the C++ is not set currently.

但是当我刚刚执行./bootstrap命令时,我得到以下错误列表,谁能建议我如何在我的系统上设置 C++ 编译器。因为我刚刚安装了 Ubuntu,可能当前没有设置 C++。

Kindly help.

请帮忙。



CMake 2.8.1, Copyright 2000-2009 Kitware, Inc.
C compiler on this system is: cc

Error when bootstrapping CMake:
Cannot find appropriate C++ compiler on this system.
Please specify one using environment variable CXX.
See cmake_bootstrap.log for compilers attempted.

Log of errors: /home/vikboy/Downloads/cmake-2.8.1/Bootstrap.cmk/cmake_bootstrap.log

回答by Ignacio Vazquez-Abrams

Install the build-essentialpackages via apt.

build-essential通过 apt安装软件包。

sudo apt-get install build-essential

回答by Kemin Zhou

I am having the same problem. Even I defined the CXX environmental variable correctly.

我有同样的问题。即使我正确定义了 CXX 环境变量。

$CXX --version g++ (GCC) 5.3.0 Copyright (C) 2015 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$CXX --version g++ (GCC) 5.3.0 版权所有 (C) 2015 Free Software Foundation, Inc. 这是免费软件;请参阅复制条件的来源。没有保修;甚至不是为了特定目的的适销性或适合性。

I looked at the log file of the ./configure output: Bootstrap.cmk/cmake_bootstrap.log

我查看了 ./configure 输出的日志文件:Bootstrap.cmk/cmake_bootstrap.log

class NeedCXX
{
public:
  NeedCXX() { this->Foo = 1; }
  int GetFoo() { return this->Foo; }
private:
  int Foo;
};
int main()
{
  NeedCXX c;
#ifdef TEST3
  cout << c.GetFoo() << endl;
#else
  std::cout << c.GetFoo() << std::endl;
#endif
  return 0;
}


/usr/bin/ld: cannot find -lgcc_s collect2: error: ld returned 1 exit status Test failed to compile Try: /usr/local/bin/g++ Line: /usr/local/bin/g++ -DTEST2 cmake_bootstrap_18998_test.cxx -o cmake_bootstrap_18998_test ---------- file -----------------------

/usr/bin/ld: 找不到 -lgcc_s collect2: 错误: ld 返回 1 退出状态 测试无法编译尝试:/usr/local/bin/g++ 行:/usr/local/bin/g++ -DTEST2 cmake_bootstrap_18998_test.cxx - o cmake_bootstrap_18998_test ---------- 文件 ---------------

The main problem is that the programmer who wrote the test did not include the include path -L/PATH/to/C++/header, that on my computer is /usr/local/include/c++/5.3.0

主要问题是写测试的程序员没有包含包含路径-L/PATH/to/C++/header,在我的电脑上是/usr/local/include/c++/5.3.0

This path should be included in the auto probing or should be an option in the configure program. I hope the cmake developers can see this message and change the auto detect a little bit.

这个路径应该包含在自动探测中或者应该是配置程序中的一个选项。我希望 cmake 开发人员可以看到此消息并稍微更改自动检测。

Or I may be wrong.

或者我可能错了。