Visual Studio 2017㨠Bash on Windows ã使ã£ã¦C++ã«ææ¡ä¸ã®ã³ã³ã»ããã試ã
ãã®è¨äºã®å 容ã¯Visual C++å ¬å¼ããã°ã¨åæ§ã«ãªãã¾ãã
Learn C++ Concepts with Visual Studio and the WSL | Visual C++ Team Blog
åºæ¬ã¯Visual C++å ¬å¼ããã°éãã«è¡ãã°ããã®ã§ãããVSä¸ã§ã®remote buildã®æ¹æ³ãå¥ã®è¨äºã«ãªã£ã¦ããããbashå´ã®ssh serviceãåããããã«windowså´ã®ãµã¼ãã¹ã1ã¤åæ¢ãããªããã°ãããªããªã©ãä¸æéãã£ãããåå¿é²ã¨ãã¦æé ãã¾ã¨ãã¾ãã
ãã®è¨äºã®ã´ã¼ã«
ä¸è¨ã®ããã°ã®ãµã³ãã«ã³ã¼ãã¨åãã§ããã以ä¸ã®ã³ã¼ããVSä¸ãããã«ãããããã°ã§ãããã¨ãç®æ¨ã«ãã¾ãã
#include <iostream> #include <type_traits> template<class T> concept bool Integral = std::is_integral<T>::value; template<class T> concept bool SignedIntegral = Integral<T> && T(-1) < T(0); template<class T> concept bool UnsignedIntegral = Integral<T> && T(0) < T(-1); template<class T> void f(T const& t) { std::cout << "Not integral: " << t << '\n'; } void f(Integral) = delete; void f(SignedIntegral i) { std::cout << "SignedIntegral: " << i << '\n'; } void f(UnsignedIntegral i) { std::cout << "UnsignedIntegral: " << i << '\n'; } int main() { f(42); f(1729u); f("Hello, World!"); enum { bar }; f(bar); f('a'); f(L'a'); f(U'a'); f(true); }
åä½ç¢ºèªããç°å¢
- Windows 10 Home 64bit ãã¼ã¸ã§ã³ 1703 OSãã«ã 15063.13
- Bash on Windows (Ubuntu 16.04.1 LTS)
- Visual Studio Community 2017 Version 15.1 (26403.3) Release æ¥æ¬èª
bashã«dbdserverã¨openssh-serverã¨gcc6ãã¤ã³ã¹ãã¼ã«ãã
bashèªä½ã®å°å ¥ã¯ä»¥ä¸è¨äºãªã©ãåç §ãã¦ãã ããã
- gdbserver
ãªã¢ã¼ã㧠GDB debuggerãå®è¡ããããã«å¿ è¦ã«ãªãã¾ã
$ sudo apt install -y gdbserver
- openssh-server
WindowsããWSLã«ã¢ã¯ã»ã¹ããããã«å¿ è¦ã«ãªãã¾ã
$ sudo apt install -y openssh-server
- gcc6
2017å¹´4ææç¹ã®WSL*1ã®OSã¯Ubuntu 16.04 LTS*2ãªã®ã§æ¨æºã®ãªãã¸ããªã«ã¯ã¾ã gcc6ç³»ãå ¥ã£ã¦ãã¾ããã*3 ãã®ããPPA*4 ããgcc6ãå°å ¥ãã¾ãã
sudo add-apt-repository ppa:ubuntu-toolchain-r/test sudo apt update sudo apt install g++-6
ãã㧠g++-6
ã¨ããååã§gcc6(æ£ç¢ºã«ã¯g++6)ã使ããããã«ãªãã¾ãã
ssh serverãå®è¡ããåã®æºå
sshãéå§ããåã«è¨å®ãå¤æ´ããç®æãããã¾ãã1度å¤æ´ããã°æ¸ã¿ã¾ãã /etc/ssh/sshd_config
ãä»»æã®ã¨ãã£ã¿ã§ç®¡çè
権éã§éãã¾ããä¾ãã°
$ sudo vi /etc/ssh/sshd_config
PasswordAuthentication
ã¨ããé
ç®ããããããã©ã«ãã§ã¯ no
ã«ãªã£ã¦ãããã yes
ã«å¤æ´ãä¿åãã¾ãã
ç¶ãã¦ãä»åº¦ã¯Windowså´ã§ç¢ºèªãããã¨ãããã¾ããssh serverã¨æ¥ç¶ãã22çªãã¼ããWindowså´ã®ãµã¼ãã¹ SSH Server Broker
ã§ä½¿ç¨ããã¦ä½¿ããªãå ´åãããã¾ãã
ã¾ã SSH Server Broker
ãåãã¦ãããã©ãã確èªããããã« services.msc
ãèµ·åãã¦ããµã¼ãã¹ä¸è¦§ã«ããããããã©ãã確èªãã¦ãã ããã
åå¨ãã¦ããããã¤ç¶æ
ãå®è¡ä¸ãªãã°åæ¢ãã¦ãã ãããåå¨ããªããã¾ãã¯å®è¡ä¸ã§ã¯ãªãå ´åã¯ä½ãããå¿
è¦ã¯ããã¾ããã
確èªã§ããããssh serverãèµ·åãã¾ããbashã«ã¦ssh keyãçæãã¾ãã
$ sudo ssh-keygen -A
ssh serverãèµ·åãã¾ããssh serverã®èµ·åã¯Visual Studioã§WSLã«æ¥ç¶ããåã«è¡ãå¿ è¦ãããã¾ãã
$ sudo service ssh start
ã¾ããBash on Windowsãéããã¨ssh serverã¯çµäºãã¾ããåã³æ¥ç¶ããã«ã¯Bash on Windowsãç«ã¡ä¸ãããåã³ $ sudo service ssh start
ãå®è¡ãã¦ãã ããã
Visual Studioã«Linuxéçºç°å¢ãå°å ¥ãã
Visual Studio 2017ãã¤ã³ã¹ãã¼ã«ãã ãã§ã¯Linuxã¨ã®ãªã¢ã¼ããã«ã&ãããã°ãããæ©è½ã¯å
¥ã£ã¦ãã¾ããã Linuxã«ããC++éçº
ã¨ãããã¼ã«ããããã¤ã³ã¹ãã¼ã«ããå¿
è¦ãããã¾ãã
Visual Studio 2017ã®ã¤ã³ã¹ãã¼ã©ã¼ãèµ·åããã¨ããã¼ã«ãããã®ã¤ã³ã¹ãã¼ã«ãè¡ããã¨ãåºæ¥ã¾ãã
ãã¤ã³ã¹ãã¼ã«æ¸ã¿ãè¦åºãã®ãVisual Studioã®é
ç®ã«ããå¤æ´ãã¨ãèµ·åãã¨ãããã¿ã³ãããã¾ãã*5
ãå¤æ´ããã¿ã³ãæ¼ãã¦ãã¯ã¼ã¯ãã¼ããã¿ããã¹ã¯ãã¼ã«ãã¾ããããããä¸å³ã®ããã«ããLinuxã«ããC++éçºãã¨ãããã¼ã«ããããã§ã¦ããã®ã§ããããã¤ã³ã¹ãã¼ã«ãã¦ãã ããã
ç¶ãã¦ãVisual Studio 2017ãèµ·åãè¨å®ãè¡ãã¾ããããã¼ã«ã>ããªãã·ã§ã³ããéãããã¤ã¢ãã°ã®å·¦ã®ããªã¼ãããã¯ãã¹ãã©ãããã©ã¼ã ããé¸æãã¾ãã å³å´ã®ã追å ããã¿ã³ãæ¼ããã©ã¼ã ã«ä»¥ä¸ãå ¥åãæ¥ç¶ãã¾ã:
- ãã¹ãå: localhost
- ãã¼ã: 22(ããã©ã«ãã®ã¾ã¾)
- ã¦ã¼ã¶å: Bash on Windowsã®ã¦ã¼ã¶åãå ¥åãã¦ãã ãã
- èªè¨¼ã®ç¨®é¡: ãã¹ã¯ã¼ã(ããã©ã«ãã®ã¾ã¾)
- ãã¹ã¯ã¼ã: Bash on Windowsã®ãã¹ã¯ã¼ã
æåããã¨ãOSåã確èªãããã¨ãåºæ¥ã¾ã(ã¦ã¼ã¶åã¯å¡ãã¤ã¶ãã¦ã¾ã)ã
ããã§ç°å¢æ§ç¯ã¯å®äºã§ããå®éã«Visual Studioã§ããã¸ã§ã¯ããä½æããLinux(WLS)ã§ãã«ã&ãããã°ãã¦ã¿ã¾ãããã
ããã¸ã§ã¯ããä½æããã«ãããããã°ãè¡ã
Visual Studio 2017ãèµ·åãããã¡ã¤ã«ã>ãæ°è¦ä½æã>ãããã¸ã§ã¯ãããé¸æããã¦ã£ã¶ã¼ããéãã¾ããä¸è¨ã®ãLinuxã«ããC++éçºããã¤ã³ã¹ãã¼ã«æ¸ã¿ã§ããã°ããã³ãã¬ã¼ãã>ãVisual C++ã>ãã¯ãã¹ãã©ãããã©ã¼ã ã>ãLinuxããããã¾ãããLinuxããéãã 空ã®ããã¸ã§ã¯ã(Linux)
ãé¸æãã¦ããã¸ã§ã¯ããä½æãã¾ãã
æ°è¦ã§C++ãã¡ã¤ã«ã追å ããããã¸ã§ã¯ãã®ããããã£ãéãã¾ããéããããæ§æããããã£ã>ãC/C++ã>ãå
¨è¬ããé¸æããC++ã³ã³ãã¤ã©ã g++-6
ã«ãã¾ãã
ä»åã¯gcc6ç³»ã®è©¦é¨å®è£
ã®conceptã試ãããã«ããã³ãã³ãã©ã¤ã³ããé¸æã -fconcepts
ã追å ãã¾ãã
ããã¾ã§æºåã§ãããããã®è¨äºã®åé ã«è²¼ã£ãã³ã¼ããã³ãããã¦ãã«ããã¾ãããããã°å®è¡ãVisual Studioä¸ããè¡ããåºåã¯Linuxã³ã³ã½ã¼ã«ã§ç¢ºèªã§ãã¾ããLinuxã³ã³ã½ã¼ã«ã¯ã¡ãã¥ã¼ããéãã¾ããããããã°ã>[Linux ã³ã³ã½ã¼ã«ãã§ãããã«ãã¨ãããã°å®è¡ã®æ¹æ³ã¯é常ã®Visual C++ãVisual C#ãªã©ã®ãã«ãããããã°ã¨åãæ¹æ³ã§è¡ãªãã¾ãã
ã¡ãªã¿ã«Linuxã®åºåãã£ã¬ã¯ããªã¯ããã¸ã§ã¯ãã®ããããã£ã®ãæ§æããããã£ããé¸æããå ¨è¬ã®ãªã¢ã¼ããã«ãã«ã¼ããã£ã¬ã¯ããªã¨ãªã¢ã¼ããã«ãããã¸ã§ã¯ããã£ã¬ã¯ããªã§å¤æ´ãããã¨ãåºæ¥ã¾ãã
åèãµã¤ã
Learn C++ Concepts with Visual Studio and the WSL | Visual C++ Team Blog
*1:Windows Subsystem for Linux
*2:creators updateé©ç¨æ¸ã¿
*3:æ®éã«sudo apt install gccããã¨5.4ãå ¥ãã¾ãã
*4:Personal Package ArchivesãUbuntuã¦ã¼ã¶ã¼ã®ãã¼ã ãå人ããããã管çãã¦ããéå ¬å¼ã®ããã±ã¼ã¸ç®¡çã·ã¹ãã ã®ãããªãã®ã§ãã allabout.co.jp
*5:Visual Studioã®æ´æ°ãããå ´åã¯ãå¤æ´ããã¿ã³ã¯ãæ´æ°ããã¿ã³ã«ãªã£ã¦ãã¾ããVisual Studioãææ°ã®ç¶æ ã«ãã¦ããæ¹ãã¦ç¢ºèªããã¦ãã ãã