在 windows 子系统上为 linux 安装 g++ [英] Installing g++ on windows subsystem for linux

查看:47
本文介绍了在 windows 子系统上为 linux 安装 g++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不久前,我在我的机器上激活了适用于 Linux 的 Windows 子系统,但并没有经常使用它.现在我知道我可以用它做什么,这就是为什么我试图在我的 WSL 上安装 gcc/++ 7 并不断遇到问题.

A while back I activated Windows Subsystem for Linux on my machine but didn't use it much. Now I have an idea what I could use it for and that is why I'm trying to install gcc/++ 7 on my WSL and keep running into problems.

我的想法是下载并按照本指南:

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

这导致了以下错误:

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:

Apparently, there was no(?) gcc installed at all. At least gcc and cc yielded "command not found". So my next step was installing gcc via:

sudo apt install gcc

这有效:

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

然而,当我从上面尝试配置命令时:

However when trying the configure command from above I got:

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程序:

So I tried to compile a simple c program by hand:

int main() {
    return 42;
}

暗示某物似乎严重损坏

$ 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:/

Any Ideas where I can even start to repair this? I wouldn't even mind reseting the whole WSL if this helps :/

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++/没有成功:

Before all of this I tried installing gcc7 / g++/ via apt without success:

$ 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.显然,更严重的东西被破坏了.

Sadly none of the suggested ways helped and I ended up nuking the WSL. Apparently, something more severe was broken.

推荐答案

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

Why compiling? You should be able to install the package:

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt update
sudo apt install g++-7 -y

验证使用:

gcc-7 --version

参见如何安装gcc-7或clang 4.0?

这篇关于在 windows 子系统上为 linux 安装 g++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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