I've blogged about the "Windows Subsystem for Linux" (also known as "Bash on Ubuntu on Windows") many times before. Response to this Windows feature has been a little funny because folks try to:
我以前写过很多关于“ Linux的Windows子系统”(也称为“ Windows上的Ubuntu上的Bash ”)的博客。 对Windows功能的React有点有趣,因为人们试图:
- Minimize it - "Oh, it's just Cygwin." (It's actually not, it's the actual Ubuntu elf binaries running on a layer that abstracts the Linux kernel.) 最小化它-“哦,这只是Cygwin。” (实际上不是,而是在抽象Linux内核的层上运行的实际Ubuntu elf二进制文件。)
- Design it - "So it's a docker container? A VM?" (Again, it's a whole subsystem. It does WAY more than you'd think, and it's FASTer than a VM.) 设计它-“所以它是一个Docker容器?一个VM?” (同样,它是一个完整的子系统。它的功能超出了您的想象,并且比VM更快。)
Here's a simple explanation from Andrew Pardoe:
这是来自Andrew Pardoe的简单解释:
1. The developer/user uses a bash shell.2. The bash shell runs on an install of Ubuntu3. The Ubuntu install runs on a Windows subsystem. This subsystem is designed to support Linux.
1.开发人员/用户使用bash shell 2。 bash shell在Ubuntu3的安装上运行。 Ubuntu安装在Windows子系统上运行。 该子系统旨在支持Linux。
It's pretty cool. WSL has, frankly, kept me running Windows because I can run cmd, powershell, OR bash (or zsh or Fish). You can run vim, emacs, tmux, and run Javascript/node.js, Ruby, Python, C/C++, C# & F#, Rust, Go, and more. You can also now run sshd, MySQL, Apache, lighttpd as long as you know that when you close your last console the background services will shut down. Bash on Windows is for developers, not background server apps. And of course, you apt-get your way to glory.
它太酷了。 坦率地说,WSL让我运行Windows,因为我可以运行cmd,powershell或bash(或zsh或Fish )。 您可以运行vim,emacs,tmux,并运行Javascript / node.js,Ruby,Python,C / C ++,C#和F#,Rust,Go等。 现在您还可以运行sshd,MySQL,Apache,lighttpd,只要您知道关闭最后一个控制台时,后台服务就会关闭。 Windows上的Bash适用于开发人员,而不适用于后台服务器应用程序。 当然,您很容易获得荣耀。
Bash on Windows runs Ubuntu user-mode binaries provided by Canonical. This means the command-line utilities are the same as those that run within a native Ubuntu environment.
Windows上的Bash运行Canonical提供的Ubuntu用户模式二进制文件。 这意味着命令行实用程序与在本地Ubuntu环境中运行的命令行实用程序相同。
I wanted to write a Linux Console app in C++ using Visual Studio in Windows. Why? Why not? I like VS.
我想使用Windows中的Visual Studio用C ++编写一个Linux控制台应用程序。 为什么? 为什么不? 我喜欢VS。
设置Visual Studio 2017以在Linux上编译和调试C ++应用 (Setting up Visual Studio 2017 to compile and debug C++ apps on Linux)
I've got Visual Studio Community, which is free for small groups and open source.
我有Visual Studio Community ,它对于小团体和开源是免费的。
If you already have it installed, make sure you run the Visual Studio Installer again (it's fast, don't worry) and select Linux:
如果已经安装了它,请确保再次运行Visual Studio Installer(速度很快,不用担心),然后选择Linux:
I've got Visual Studio Community, which is free for small groups and open source.
我有Visual Studio Community ,它对于小团体和开源是免费的。
I make sure my Windows 10 is up to date and has Bash on Ubuntu installed.
我确保Windows 10是最新的,并且在Ubuntu上安装了Bash 。
The "Windows 10 Creators Edition" is out April 11th but if you're a Windows Insider or use the Update Assistant you can get it on April 5th. It includes a bunch of improvements to Bash on Windows (release notes)
“ Windows 10 Creators Edition”将于4月11日发布,但是如果您是Windows Insider或使用Update Assistant,则可以在4月5日获得它。 它包括对Windows上Bash的大量改进(发行说明)
I make sure my Windows 10 is up to date and has Bash on Ubuntu installed.
Then, from the bash shell make sure you have build-essential, gdb's server, and openssh's server:
然后,从bash shell确保您具有build-essential,gdb的服务器和openssh的服务器:
$ sudo apt update
$ sudo apt install -y build-essential
$ sudo apt install -y gdbserver
$ sudo apt install -y openssh-server
Then open up /etc/ssh/sshd_config with vi (or nano) like
然后使用vi(或nano)打开/ etc / ssh / sshd_config
sudo nano /etc/ssh/sshd_config
and for simplicity's sake, set PasswordAuthentication to yes. Remember that it's not as big a security issue as you'd think as the SSHD daemon closes when your last console does, and because WSL's subsystem has to play well with Windows, it's privy to the Windows Firewall and all its existing rules, plus we're talking localhost also.
为了简单起见,请将PasswordAuthentication设置为yes 。 请记住,当您的最后一个控制台关闭时,SSHD守护程序关闭时,安全问题并不像您想象的那么大,并且由于WSL的子系统必须在Windows上正常运行,因此Windows防火墙及其所有现有规则是私有的,此外我们也正在谈论本地主机。
Now generate SSH keys and manually start the service:
现在生成SSH密钥并手动启动该服务:
$ sudo ssh-keygen -A
$ sudo service ssh start
Create a Linux app in Visual Studio (or open a Makefile app):
在Visual Studio中创建Linux应用(或打开Makefile应用):
![File | New Project | Cross Platform | Linux File | New Project | Cross Platform | Linux](https://i-blog.csdnimg.cn/blog_migrate/7aefd8060ca5f47de00b6ccab0b53595.png)
Make sure you know your target (x64, x86, ARM):
确保您知道目标(x64,x86,ARM):
![Remote GDB Debugger options Remote GDB Debugger options](https://i-blog.csdnimg.cn/blog_migrate/d9de6f837636e043840a33061c7d5716.png)
In Visual Studio's Cross Platform Connection Manager you can control your SSH connections (and set up ones with private keys, if you like.)
在Visual Studio的跨平台连接管理器中,您可以控制SSH连接(并根据需要设置私钥)。
![Tools | Options | Cross Platfrom | Connection Manager Tools | Options | Cross Platfrom | Connection Manager](https://i-blog.csdnimg.cn/blog_migrate/03b1a6aa472575f3cca331a47cca905e.png)
Boom. I'm writing C++ for Linux in Visual Studio on Windows...running, compiling and debugging on the local Linux Subsystem
繁荣。 我正在Windows的Visual Studio中为Linux编写C ++ ...在本地Linux子系统上运行,编译和调试
![I'm writing C++ in Visual Studio on Windows talking to the local Linux Subsystem I'm writing C++ in Visual Studio on Windows talking to the local Linux Subsystem](https://i-blog.csdnimg.cn/blog_migrate/00130c2d834ad895a4acf0dbc4ce334b.png)
BTW, for those of you, like me, who love your Raspberry Pi tiny Linux computers...this is a great way to write C++ for those little devices as well. There's even a Blink example in File | New Project to start.
顺便说一句,对于喜欢我的Raspberry Pi小型Linux计算机的你们这些人来说……这也是为这些小型设备编写C ++的好方法。 文件|甚至还有一个Blink示例。 新项目开始。
Also, for those of you who are very advanced, stop using Mingw-w64 and do cool stuff like compiling gcc 6.3 from source under WSL and having VS use that! I didn't realize that Visual Studio's C++ support lets you choose between a number of C++ compilers including both GCC and Clang.
另外,对于那些非常高级的人,请停止使用Mingw-w64并做一些很酷的事情,例如在WSL下从源代码编译gcc 6.3并让VS使用它! 我没有意识到Visual Studio的C ++支持可以让您在许多C ++编译器(包括GCC和Clang)之间进行选择。