首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在用于linux的windows子系统上安装g++

在用于linux的windows子系统上安装g++
EN

Stack Overflow用户
提问于 2018-06-07 05:02:53
回答 3查看 18.5K关注 0票数 11

不久前,我在我的机器上激活了Windows Subsystem for Linux,但并没有太多地使用它。现在我有了一个想法,我可以使用它来做什么,这就是为什么我试图在我的无线WSL上安装gcc/++ 7,但总是遇到问题。

我的想法是对它进行download,然后在this guide之后手工编译它:

代码语言:javascript
复制
../gcc/configure -v --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --prefix=${HOME}/software/gcc-7.3.0/installDir --enable-checking=release --enable-languages=c,c++,fortran --disable-multilib

这导致了以下错误:

代码语言:javascript
复制
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
checking LIBRARY_PATH variable... ok
checking GCC_EXEC_PREFIX variable... ok
checking whether to place generated files in the source directory... no
checking whether a default linker was specified... no
checking whether a default assembler was specified... no
checking for x86_64-linux-gnu-gcc... no
checking for gcc... no
checking for x86_64-linux-gnu-cc... no
checking for cc... no
checking for x86_64-linux-gnu-cl.exe... no
checking for cl.exe... no
configure: error: in `$HOME/software/gcc-7.3.0/build':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details.

显然,没有(?)gcc根本就装不上。至少gcccc生成了“未找到命令”。所以我的下一步是通过以下方式安装gcc:

代码语言:javascript
复制
sudo apt install gcc

这是可行的:

代码语言:javascript
复制
$ gcc --version
gcc (Ubuntu 4.8.4-2ubuntu1~14.04.4) 4.8.4 
Copyright (C) 2013 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.

然而,当尝试上面的configure命令时,我得到了:

代码语言:javascript
复制
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu 
checking LIBRARY_PATH variable... ok
checking GCC_EXEC_PREFIX variable... ok
checking whether to place generated files in the source directory... no
checking whether a default linker was specified... no
checking whether a default assembler was specified... no
checking for x86_64-linux-gnu-gcc... x86_64-linux-gnu-gcc
checking for C compiler default output file name...
configure: error: in `/home/seriously-ubuntu/software/gcc-7.3.0/build':
configure: error: C compiler cannot create executables
see `config.log' for more details.

所以我试着手工编译一个简单的c程序:

代码语言:javascript
复制
int main() {
    return 42;
}

这暗示着有些东西似乎严重损坏了

代码语言:javascript
复制
$ gcc foo.c
/usr/bin/ld: cannot find crt1.o: No such file or directory
/usr/bin/ld: cannot find crti.o: No such file or directory
/usr/bin/ld: cannot find -lc
/usr/bin/ld: cannot find crtn.o: No such file or directory
collect2: error: ld returned 1 exit status

你知道我该从哪里开始修复它吗?我甚至不介意重置整个WSL,如果这有帮助的话:/

代码语言:javascript
复制
lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.3 LTS
Release:        16.04
Codename:       xenial

更新:

在此之前,我尝试通过apt安装gcc7 / g++/,但没有成功:

代码语言:javascript
复制
$ sudo add-apt-repository ppa:jonathonf/gcc-7.1
$ sudo apt-get update
$ sudo apt-get install gcc-7 g++-7
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
g++-7 : Depends: libstdc++-7-dev (= 7.1.0-10ubuntu1~16.04.york0) but it is not going to be installed
        Depends: libisl15 (>= 0.15) but it is not installable 
gcc-7 : Depends: cpp-7 (= 7.1.0-10ubuntu1~16.04.york0) but it is not going to be installed
        Depends: binutils (>= 2.26.1) but 2.24-5ubuntu14.2 is to be installed
        Depends: libisl15 (>= 0.15) but it is not installable
        Recommends: libc6-dev (>= 2.13-0ubuntu6) but it is not going to be installed
E: Unable to correct problems, you have held broken packages

更新2

遗憾的是,所有建议的方法都没有帮助,我最终销毁了WSL。显然,一些更严重的东西被打破了。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2018-06-07 05:05:21

为什么要编译?您应该能够安装该程序包:

代码语言:javascript
复制
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt update
sudo apt install g++-7 -y

使用以下命令进行验证:

代码语言:javascript
复制
gcc-7 --version

请参阅How to install gcc-7 or clang 4.0?

票数 12
EN

Stack Overflow用户

发布于 2018-06-08 13:39:00

运行以下命令

代码语言:javascript
复制
sudo apt install aptitude
sudo aptitude install gcc-7 g++-7

代码语言:javascript
复制
sudo apt install aptitude && sudo aptitude install golang gcc-7 g++-7
票数 4
EN

Stack Overflow用户

发布于 2018-06-07 07:05:48

crt1.o通常是作为libdevc依赖项(或类似的东西)的一部分提供的。我建议在lib6clibdevlibc-dev等平台上运行sudo apt search libc或类似的变种。安装它们修复了我最近遇到的类似问题。

如果失败,请运行find / -iname ctri.o并使用export PATH="[folder]:$PATH"将它所在的文件夹添加到您的路径中,看看这是否有帮助。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50729550

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档