在windows子系统上为linux

时间:2018-06-06 21:02:53

标签: linux gcc ubuntu-16.04 apt windows-subsystem-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。至少gcccc未找到"命令"。所以我的下一步是通过以下方式安装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。显然,更严重的事情被打破了。

3 个答案:

答案 0 :(得分:5)

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

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?

答案 1 :(得分:2)

运行以下

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
    Bundle bundle = getArguments();
        Double sum = bundle.getDouble("sum_key");
}

sudo apt install aptitude
sudo aptitude install gcc-7 g++-7

答案 2 :(得分:1)

crt1.o通常作为libdevc依赖项(或类似内容)的一部分提供。我建议使用sudo apt search libclib6clibdev等运行libc-dev或某些类似的变体。安装这些变体修复了我最近遇到的类似问题。

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