系统相关
首页 > 系统相关> > 在Windows子系统上安装g for linux

在Windows子系统上安装g for linux

作者:互联网

前段时间我在我的机器上激活了Windows子系统Linux,但没有使用它.现在我知道我可以使用它,这就是为什么我试图在我的WSL上安装gcc / 7并继续遇到问题.

我的想法是download它并在this guide之后用手编译:

../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.至少gcc和cc产生了“未找到命令”.所以我的下一步是通过以下方式安装gcc:

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.

但是当从上面尝试configure命令时,我得到了:

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

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

lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.3 LTS
Release:        16.04
Codename:       xenial

更新:

在所有这些之前,我尝试安装gcc7 / g / via apt但没有成功:

$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.显然,更严重的事情被打破了.

解决方法:

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

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

验证使用:

gcc-7 --version

How to install gcc-7 or clang 4.0?

标签:windows-subsystem-for-linux,linux,gcc,ubuntu-16-04,apt
来源: https://codeday.me/bug/20190910/1799300.html