Windowsä¸ã§ã®C/C++ããã°ã©ã ã®éçºã«ã¯Visual C++ï¼in Visual Studioï¼ã使ãã®ãä¸è¬çã ããããã¯ããã¾ã§Windowså®å ¨ä¾åã®ãã¤ãã£ãã»ããã°ã©ã ãéçºããããã®ç°å¢ã ã
æããWindowsä¸ã«Unixäºæç°å¢ãæ§ç¯ãã試ã¿ãè¡ããã¦ãã¦ããã®é大æçãªããã¸ã§ã¯ãã¨ãã¦1995å¹´ã«ç»å ´ããCygwinã¨ãããã®ããããå°çã¯10å¹´åã¾ã§çµã¿è¾¼ã¿éçºãå°éåéã ã£ãã®ã§ãWindowsä¸ã«Cygwinå°å ¥ãã¦ã¯ãã¹GCCã³ã³ãã¤ã©ããã使ã£ã¦ãããã®ã ãçµã¿è¾¼ã¿å±ã«ã¨ã£ã¦ã®Cygwinã®å©ç¨ä¾¡å¤ã¯ãã®ä¸ç¹ã ãã ã£ãã®ã§ãä»®æ³ãã·ã³ã»ãã¼ã«ã®æ®åãDockerãWSLã®ç»å ´ã«ãã£ã¦ããã¾ã§ã¯Cygwinã使ããã¨ã¯ãªããªã£ã¦ãã¾ã£ãã
GCCã使ã£ã¦Windowsç¨ããã°ã©ã ãéçºãããããããã¯Unix/Linuxããã°ã©ã ãWindowsã¸ç§»æ¤ãããã¨ããè¦æã¯æãããã£ã¦ãããã«å¿ããéçºç°å¢ããã¸ã§ã¯ãã¨ãã¦MinGW-W64ï¼32ãããçMinGWããã¸ã§ã¯ããããã©ã¼ã¯ãã64ããã対å¿çï¼ã¨ããã®ãããã
MinGWã¯Cygwinãããã©ã¼ã¯ããããã¸ã§ã¯ãã ããCygwinã®ææãå¸åãã¦çºå±ãããã¾ã§ã¯Unixäºæéçºç°å¢ã¨ãã¦ã¯MinGWã®æ¹ãã¡ã¸ã£ã¼ã«ãªã£ã¦ããã
éçºãã©ãããã¼ã ã¨ãã¦MacãLinuxãWindowsãä½µç¨ããããã«ãªããLinuxç¨ããã°ã©ã ãWindowsã¸ç§»æ¤ããªããã°ãªããªãã±ã¼ã¹ãåºã¦ããã®ã§ãWindowsæ©ã«MinGW-W64ãå°å ¥ããã
ã°ã°ãã¨åæ§ã®è¨äºã¯å¤ãããããèªåã®åå¿é²ã¨ãã¦ãMinGW-w64ã®ã¤ã³ã¹ãã¼ã«ã¨ç°å¢æ§ç¯æ¹æ³ãæ¸ãã¦ããã
MSYS2ã®ã¤ã³ã¹ãã¼ã«
MinGWããã¸ã§ã¯ãã®ææç©ã¨ãã¦MSYSï¼MSYS2ï¼ã¨ããã®ããããããã¯Bashã·ã§ã«ç°å¢ã¨ã³ãã³ã群ãã¾ã¨ãããã®ã§ãMinGW-w64ã¨ã¯å¥ã®ããã¸ã§ã¯ãã ããMinGW-W64ã¨MSYS2ãä¸ç·ã«ä½¿ããã¨ã§ãUnixã©ã¤ã¯ãª64ãããçWindowsç¨ããã°ã©ã ã®éçºç°å¢ãæ§ç¯ã§ããã
MSYS2ã®ãµã¤ãããããã®ï¼ã¤ãçµ±åããç°å¢ã®ã¤ã³ã¹ãã¼ã©ãå
¥æãããã¨ãã§ããï¼æ¬è¨äºå·çæç¹ã§ã®ææ°çã¤ã³ã¹ãã¼ã©ã¯msys2-x86_64-20240113.exe
ï¼ã
ãã¤ã¯ãMinGW-W64 + MSYS2ãå°å ¥ããã®ã¯ãããããã®MSYS2ã®Bashã¿ã¼ããã«ç°å¢ãå©ç¨ãããã¨ãåªå ç®çã ã£ããããï¼MacãLinuxã®ã¿ã¼ããã«ç°å¢ã«æ £ãã¦ããã¨ãPowerShellãã³ãã³ãããã³ããã使ãã®ã¯è¦çãªã®ã§ãYouTubeä¸ã§ã®ããã°ã©ãã³ã°ã»éçºç³»è©±é¡ã®åç»å ã§Windowsç°å¢ãå©ç¨ãã¦ããå ´é¢ã§ããã®MinGW-w64 + MSYS2ã使ããã¦ããã®ãå¤ã観ããããVisual Studio Codeã¨åæ§ã«ããã¾ã¯ãããWindowså©ç¨éçºã§ã®å®çªç°å¢ã¨ãªã£ã¦ããããã ï¼ã
ã¤ã³ã¹ãã¼ã©ã®ã¬ã¤ã表示ã«å¾ã£ã¦æä½ããã¨ãMSYS2ã®ããã©ã«ãã®ã¤ã³ã¹ãã¼ã«å
ãã£ã¬ã¯ããªã¯C:\msys64
ã«ãªãã
ã¾ããä¸ã®ï¼ã¤ã®ã¢ããªã»ã¢ã¤ã³ã³ãã¹ã¿ã¼ãã¡ãã¥ã¼å ã«ä½æãããã
ãããã®ã¢ã¤ã³ã³ã«ãã£ã¦èµ·åããåç°å¢ã§ã¯ããã®ä¸ã§ä½¿ç¨ãããã³ã³ãã¤ã©ã»ãã¼ã«ãã§ã¤ã³ãã¿ã¼ã²ããã»ã¢ã¼ããã¯ãã£ãã©ã³ã¿ã¤ã ã»ã©ã¤ãã©ãªã®ç¨®é¡ã以ä¸ã®ããã«ç°ãªã£ã¦ããã
ã¢ããªã»ã¢ã¤ã³ã³ | ãã¼ã«ãã§ã¤ã³æ ¼ç´å ´æ | ã³ã³ãã¤ã© | ã¿ã¼ã²ããã¢ã¼ããã¯ã㣠| ã©ã³ã¿ã¤ã ã©ã¤ãã©ãª |
---|---|---|---|---|
MSYS2 MSYS | /usr |
gcc | x86_64 (Intel 64ããã) | cygwin |
MSYS2 UCRT64 | /ucrt64 |
gcc | x86_64 (Intel 64ããã) | ucrt |
MSYS2 CLANG64 | /clang64 |
llvm | x86_64 (Intel 64ããã) | ucrt |
MSYS2 CLANGARM64 | /clangarm64 |
llvm | aarch64 (ARM 64ããã) | ucrt |
MSYS2 MINGW32 | /mingw32 |
gcc | i686 (Intel 32ããã) | msvcrt |
MSYS2 MINGW64 | /mingw64 |
gcc | x86_64 (Intel 64ããã) | msvcrt |
Linuxç¨C/C++ããã°ã©ã ã¯ã»ã¨ãã©GCCã使ã£ã¦ä½æããã¦ããã®ã§ãLinuxããã°ã©ã ã®64ãããçWindowsã¸ã®ç§»æ¤ã«å©ç¨ããã®ã¯MSYS2 MINGW64
ã«ãªãï¼GCCãã¼ã¹ã®Intel 64ãããçWindowsããã°ã©ã ã®éçºã»ç§»æ¤ãããããªããªãããã以å¤ã¯å©ç¨ãããã¨ã¯ãªããããããªãï¼ã
MinGW-w64ã®åæè¨å®
ç°å¢å¤æ°ã®è¨å®
MSYS2ã®ã¤ã³ã¹ãã¼ã«ãçµãã£ãããã·ã¹ãã ç°å¢å¤æ°ã«"MSYSTEM
"ï¼"MINGW64
"ã¨ããè¨å®ãä½æãã¦ããã
管çè 権éã§PowerShellãéãã¦ãä¸ã®ã³ãã³ããå®è¡ãããã¨ã§ããã®è¨å®æä½ãè¡ããã
> [System.Environment]::SetEnvironmentVariable("MSYSTEM", "MINGW64", "Machine")
ããã«ãã¦ã¼ã¶ã¼ç°å¢å¤æ°Path
ã«ä»¥ä¸ã®ãã¹ã追å ããã
C:\msys64\mingw64\bin
C:\msys64\usr\local\bin
C:\msys64\usr\bin
C:\msys64\bin
C:\msys64\opt\bin
PowerShellãéãã¦ã以ä¸ã®ã³ãã³ããå®è¡ãããã¨ã§ããã®è¨å®æä½ãè¡ããã
> $oldpath = [System.Environment]::GetEnvironmentVariable("Path", "User"); $oldpath += ";C:\msys64\mingw64\bin"; [System.Environment]::SetEnvironmentVariable("Path", $oldpath, "User") > $oldpath = [System.Environment]::GetEnvironmentVariable("Path", "User"); $oldpath += ";C:\msys64\usr\local\bin"; [System.Environment]::SetEnvironmentVariable("Path", $oldpath, "User") > $oldpath = [System.Environment]::GetEnvironmentVariable("Path", "User"); $oldpath += ";C:\msys64\usr\bin"; [System.Environment]::SetEnvironmentVariable("Path", $oldpath, "User") > $oldpath = [System.Environment]::GetEnvironmentVariable("Path", "User"); $oldpath += ";C:\msys64\bin"; [System.Environment]::SetEnvironmentVariable("Path", $oldpath, "User") > $oldpath = [System.Environment]::GetEnvironmentVariable("Path", "User"); $oldpath += ";C:\msys64\opt\bin"; [System.Environment]::SetEnvironmentVariable("Path", $oldpath, "User")
ãããã®ç°å¢å¤æ°ã¯ãã³ãã³ãããã³ãããPowerShellãªã©ã®MSYS2ã·ã§ã«ä»¥å¤ã®ã¿ã¼ããã«ç°å¢ããMinGW-w64ã®ã³ãã³ã群ãåç §å¯è½ã«ããããã®è¨å®ã ã
ããã±ã¼ã¸ã®æ´æ°
ã¢ããªMSYS2 MINGW64
ãèµ·åãã¦ãéããã·ã§ã«ç»é¢ããä¸ã®ã³ãã³ããå®è¡ããã
$ pacman -Syu
ããã«ãã£ã¦ãããã±ã¼ã¸ãã¼ã¿ãã¼ã¹æ å ±ãpacmanã³ãã³ããã³ã¢ããã±ã¼ã¸ãæ´æ°ãããã
ããä¸åº¦MSYS2 MINGW64
ãéãã¦ãä¸ã®ã³ãã³ããå®è¡ããã
$ pacman -Su
ããã«ãã£ã¦ãæ¢åã®å ¨ããã±ã¼ã¸ãæ´æ°ãããã
ã¦ã¼ã¶ã¼ã»ãã¼ã ãã£ã¬ã¯ããªã®å¤æ´
MSYS2ã·ã§ã«å
ã§ã®ã¦ã¼ã¶ã¼ã»ãã¼ã ãã£ã¬ã¯ããª/home/USERNAME
ã¯ãã¹C:\msys64\home\USERNAME
ã«å²ãå½ã¦ããã¦ããã
ããã¯ã¦ã¼ã¶ã¼ã®å¥½ã¿æ¬¡ç¬¬ã ãã以ä¸ã®ãã¡ã¤ã«ãç·¨éãããã¨ã§ããã®ãã¹ãC:\Users\USERNAME
ã«å¤æ´ãããã¨ãã§ããã
C:\msys64\etc\nsswitch.conf
ï¼MSYS2ã·ã§ã«å ãã¹/etc/nsswitch.conf
ï¼
-db_home: cygwin desc +#db_home: cygwin desc +db_home: windows
ãã®å¤æ´ãè¡ã£ãå ´åã¯ãMSYS2ã·ã§ã«ããä¸ã®ãããªã³ãã³ããå®è¡ãã¦ããã¹ã¦ã®è¨å®ã¹ã¯ãªãããã¡ã¤ã«ãC:\msys64\home\USERNAME
ããC:\Users\USERNAME
ã¸ã³ãã¼ãã¦ããã¹ãã ã
$ cd $ cp -p /c/msys64/home/USERNAME/.profile /c/msys64/home/USERNAME/.bash_profile /c/msys64/home/USERNAME/.bash_logout /c/msys64/home/USERNAME/.bashrc .
GCCã®ã¤ã³ã¹ãã¼ã«ã¨åä½ç¢ºèª
GCCããã±ã¼ã¸ã®ã¤ã³ã¹ãã¼ã«
MSYS2 MINGW64
ã·ã§ã«ãã以ä¸ã®ã³ãã³ããå®è¡ããã°ãGCCã³ã³ãã¤ã©ããã³ãã®é¢é£ããã±ã¼ã¸ç¾¤ãã¤ã³ã¹ãã¼ã«ã§ããã
$ pacman -S base-devel $ pacman -S mingw-w64-x86_64-toolchain
ã¤ã³ã¹ãã¼ã«å¾ã以ä¸ã®ï¼ã¤ã®ã³ãã³ããå®è¡ãã¦ãGCCã³ã³ãã¤ã©ãå©ç¨ã§ãããã¨ã確èªãã¦ããã
$ gcc --version $ g++ --version $ cpp --version
GCCã«ããã³ã³ãã¤ã«ç¢ºèª
é©å½ãªã¨ãã£ã¿ã使ã£ã¦ã以ä¸ã®ãããªã½ã¼ã¹ã»ãã¡ã¤ã«ãä½æããã
#include <stdio.h> int main() { printf("Hello, world!\n"); printf("sizeof(size_t) = %ld\n", sizeof(size_t)); return 0; }
MSYS2 MINGW64
ã·ã§ã«ãéããä¸ã®ã³ãã³ããå®è¡ããã°ãæ¬ã½ã¼ã¹ãã³ã³ãã¤ã«ãããã
$ gcc hello.c
ç¶ãã¦ãä¸ã®ã³ãã³ããå®è¡ããã°ãã³ã³ãã¤ã«çæãããããã°ã©ã ãå®è¡ãããã¨ãã§ããã
$ ./a.exe Hello, world! sizeof(size_t) = 8
ãåç §ãªã³ã¯ã