Installing g++ on windows subsystem for linux
Why compiling? You should be able to install the package:
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt update
sudo apt install g++-7 -y
Verify using:
gcc-7 --version
See How to install gcc-7 or clang 4.0?
How to install GCC and GDB for WSL(windows subsytem for linux)?
You need to:
- Update and upgrade:
$ sudo apt-get update && sudo apt-get upgrade -y
2.Clean unrequired packages:
$ sudo apt autoremove -y
- Install GCC:
$ sudo apt-get install gcc -y
- Check and confirmed installed gcc version:
gcc --version
Is it possible to compile from Windows to Linux with gcc/g++?
You have several choices:
- WSL.
WSL(Windows Subsystem for Linux) its linux termanal in windows, so you can compile linux code in windows. This solution is the simpliest and I would recommend to use it. - Visual studio.
Visual studio has a package that allows you to compile programs for Linux. More details here
Newly installed g++ on wsl has problem recognizing c++11 STL types
The std::shared_mutex was not provided until c++ 17. https://en.cppreference.com/w/cpp/thread/shared_mutex
So to fix this issue, you just need to change the compilation command to
g++ rwlock.cpp -std=c++17
How to compile executable for Windows with GCC with Linux Subsystem?
Linux Subsystem works as a Linux-computer. You can only run Linux executables inside it and default gcc
creates Linux executables.
To create Windows executables, you need to install mingw cross-compiler:
sudo apt-get install mingw-w64
Then you can create 32-bit Windows executable with:
i686-w64-mingw32-gcc -o main32.exe main.c
And 64-bit Windows executable with:
x86_64-w64-mingw32-gcc -o main64.exe main.c
Note that these Windows executables will not work inside Linux Subsystem, only outside of it.
Related Topics
Svg to PDF on a Shared Linux Server
Linux Udp Max Size of Receive Buffer
How to Get Notified for Ip Address Changes Automatically
Print Kernel's Page Table Entries
Arm Linux Atags VS Device Tree
How Does Stat Command Calculate the Blocks of a File
Udev - Run Program on Usb Flash Drive Insert
Dma Cache Coherence Management
How to Split a Ca Certificate Bundle into Separate Files
Determine If Relative or Absolute Path in Shell Program
Ubuntu Equivalent of Yum's Whatprovides, to Find Which Package Provides a File
How to Read a Sector Using a Bio Request in Linux Kernel
Linker Cannot Find Symbols, But Libraries Are Read and Symbols Exist
How to Check If a Files Exists in a Specific Directory in a Bash Script