C++ 在没有root权限的linux上安装gcc

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3212099/
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 12:20:06  来源:igfitidea点击:

Install gcc on linux with no root privilege

c++linuxgccg++

提问by Matthew Murdock

I have access to computer in a public library and I want to try out some C++ and maybe other code. Problem is that there is no g++ installed and I can't install it using packages because I have no root access. Is there a "smart" way to make a full environment for programming in a home folder?

我可以访问公共图书馆中的计算机,我想尝试一些 C++ 和其他代码。问题是没有安装 g++,我无法使用包安装它,因为我没有 root 访问权限。是否有一种“智能”方法可以在主文件夹中创建完整的编程环境?

I have gcc installed (I can compile C code). Also, I have a home folder that is consistent. I don't know where to find precompiled g++, I found only source but I don't know what to do with it. I tried to ask them to install this but it didn't work :)

我已经安装了 gcc(我可以编译 C 代码)。另外,我有一个一致的主文件夹。我不知道在哪里可以找到预编译的 g++,我只找到了源代码,但我不知道如何处理它。我试图让他们安装这个,但没有用 :)

回答by Rudi

You can run the configure script with the --prefix parameter: ../gcc-4.5.0/configure --prefix=/home/foo/bar. Since it is very likely that the c++ standard library is different then the one on your system, you have to set export LD_LIBRARY_PATH=/home/foo/bar/libbefore you can start a program compiled by this compiler.

您可以运行与--prefix参数配置脚本:../gcc-4.5.0/configure --prefix=/home/foo/bar。由于 c++ 标准库很可能与您系统上的标准库不同,因此您必须先进行设置,export LD_LIBRARY_PATH=/home/foo/bar/lib然后才能启动由该编译器编译的程序。

回答by DanielY

If you want to install it as a local user

如果您想以本地用户身份安装它

GNU GSRC provides an easy way to do so

GNU GSRC 提供了一种简单的方法来做到这一点

Link: http://www.gnu.org/software/gsrc/

链接:http: //www.gnu.org/software/gsrc/

After configuration, simply specify the following commands:

配置完成后,只需指定以下命令:

cd gsrc
make -C pkg/gnu/gcc 
make -C pkg/gnu/gcc install

The second step could also be changed to speed up for an N-core system:

也可以更改第二步以加快 N 核系统的速度:

make -C pkg/gnu/gcc MAKE_ARGS_PARALLEL="-jN"

回答by Omnifarious

Once, a long time ago (1992 or so), I went through something similar to this when I bought a SCO system with no development environment. Bootstrapping it up to having a full development environment was a gigantic pain, and not at all easy. Having library header files or gcc on a system would make your job a whole lot easier.

有一次,很久以前(1992年左右),我买了一个没有开发环境的SCO系统,也经历过类似的事情。将它引导到拥有完整的开发环境是一个巨大的痛苦,而且一点也不容易。在系统上拥有库头文件或 gcc 会让你的工作变得更容易。

It depends a lot on just how obnoxious the library has been about what kinds of things are installed. If there is no gccthere, your job becomes a bit harder. If there are no header files for glibc there, your job is a LOT harder.

这在很大程度上取决于库对安装的东西的讨厌程度。如果没有gcc,你的工作会变得有点困难。如果那里没有 glibc 的头文件,那么您的工作就会困难得多。

Also, do you get an account on the system so you have a home folder that's consistent from login to login?

另外,您是否在系统上获得了一个帐户,以便您拥有一个从登录到登录都一致的主文件夹?

If you have no gccthere, you need to find a pre-compiled binary of gcc/g++ and install it somewhere. If you have no header files there, you need to find copies of those and put them on the system.

如果没有gcc,则需要找到 gcc/g++ 的预编译二进制文件并将其安装在某处。如果那里没有头文件,则需要找到它们的副本并将它们放在系统上。

There is no 'standard' way of installing gcc in your home folder though. All of the solutions are going to have some manner of hand-rolling involved.

但是,没有在您的主文件夹中安装 gcc 的“标准”方式。所有的解决方案都将涉及某种方式的手动滚动。

Have you asked the librarians if they can change what's installed because you want to learn a bit of programming and only have access to their computers to do it with? That might well be the easiest solution.

你有没有问过图书馆员他们是否可以更改安装的内容,因为你想学习一点编程并且只能访问他们的电脑来做这些?这可能是最简单的解决方案。

From your comment it seems that you do have gccand if you can compile C code, you have the library header files. So now it's a matter of actually compiling your own version of g++. You could probably find a way to entice the package manager on the system into installing a binary package somewhere other than in a system folder. I think this solution is less fun than compiling your own, and I think there may also be possible subtle problems as that installed package may be expecting to find things in particular places and not finding them there.

从您的评论看来,您确实拥有,gcc并且如果您可以编译 C 代码,那么您就有了库头文件。所以现在是实际编译您自己的g++. 您可能会找到一种方法来诱使系统上的包管理器将二进制包安装到系统文件夹以外的其他位置。我认为这个解决方案没有编译自己的解决方案那么有趣,而且我认为也可能存在一些微妙的问题,因为安装的包可能希望在特定的地方找到东西,而在那里找不到。

First thing to do is to make sure you've downloaded the right source for the gcc package. The place to find that is the GNU United States mirror page. You want to find the gcc-4.5.0.tar.bz2or gcc-4.5.0.tar.gzfile on the mirror site you choose. It will likely be in a gccdirectory, and a gcc-4.5.0sub-folder.

首先要做的是确保您已经下载了 gcc 包的正确源代码。找到的地方是GNU 美国镜像页面。您想在您选择的镜像站点上找到gcc-4.5.0.tar.bz2gcc-4.5.0.tar.gz文件。它可能位于一个gcc目录和一个gcc-4.5.0子文件夹中。

After you have that downloaded, you should untar it. In general you shouldn't build gcc in the folder you untar it into. So create another sibling folder that you actually want to build it in labeled gcc-build. Then the command you want is ../gcc-4.5.0/configure --prefix=$HOME/.local --enable-languages='c c++'.

下载后,您应该解压缩它。一般来说,您不应该在解压到的文件夹中构建 gcc。因此,创建另一个同级文件夹,您实际上希望将其构建在标记为gcc-build. 那么你想要的命令是../gcc-4.5.0/configure --prefix=$HOME/.local --enable-languages='c c++'.

gcc does require some other packages be installed in order to be able to compile itself. You can use the same --prefixline for these packages to install them in the same place. The gcc website has a list of pre-requisite packages.

gcc 确实需要安装一些其他软件包才能自行编译。您可以--prefix对这些包使用相同的行以将它们安装在同一位置。gcc 网站有一个先决条件包列表

$HOME/.localis sort of the standard accepted place for per-user installs of things.

$HOME/.local是每个用户安装东西的标准接受的地方。

回答by reece

If you have fakeroot, you can use that to set ~/some-path as root to install the packages from. Alternatively, you can setup a chroot environment to do the same.

如果您有 fakeroot,您可以使用它来将 ~/some-path 设置为 root 来安装软件包。或者,您可以设置一个 chroot 环境来执行相同的操作。

Given this, you can then use dpkg -i package.debto install the gcc package(s) on your system. You will need to download and install each package individually (e.g. from the debian website) -- at least binutils, glibc, linux-headersand gcc.

鉴于此,您可以使用dpkg -i package.deb在您的系统上安装 gcc 包。您将需要下载并分别安装每个包(例如,从Debian网站) -至少binutilsglibclinux-headersgcc

If you are on another system, you will need to get the right packages for that system and install them using the corresponding package manager.

如果您在另一个系统上,则需要为该系统获取正确的软件包并使用相应的软件包管理器安装它们。