Why is MSYS2 using non-standard terminal colors? - color-scheme

I have been trying to figure this out for a couple hours and it has left me confused.
I have installed MSYS2 on Windows 10, and added it as a profile to windows terminal by adding the following snippet to the profiles section of my settings.json:
{
"commandline": "C:/msys64/msys2_shell.cmd -defterm -here -no-start -mingw64",
"guid": "{17da3cac-b318-431e-8a3e-7fcdefe6d114}",
"icon": "C:/msys64/mingw64.ico",
"name": "MINGW64 / MSYS2",
"startingDirectory": "C:/msys64/home/%USERNAME%"
}
Which works great, however terminal colors don't seem to behave like I would expect.
Here are two images showing vim with the :colo ron option showing the difference between a WSL Ubuntu profile and the MSYS2 profile:
The colors in the WSL profile look like I would expect them to, while the ones in the MSYS2 profile look strange. Both profiles are set to use the same color profile (Campbell) in the Windows Terminal settings. MSYS2 shows the same strange colors when I run it through the included mintty terminal instead of Windows Terminal. If I use MSYS2 to ssh to a different Ubuntu machine, all colors look like I would expect. In all cases (the WSL profile, the MSYS2 profile, and on the remote Ubuntu machine), the $TERM environment variable is set to xterm-256color.
Any ideas what is causing this?

Related

Error in VSCode for Windows using Linux header

I'm using VS Code on Windows 10 and have written some C code. In the code, I need to use the sys/wait.h header. Since that is a Linux-specific header, I need to compile and run with WSL2 using Ubuntu as a subsystem.
The code compiles and works with WSL but VS Code gives me the following error:
#include errors detected. Please update your includePath.
My guess is it's because my current includePath points to GCC on my Windows machine and not to WSL, which is why it can't find this header. Is there a way for me to also include the headers found in WSL Ubuntu or do I have to live with this annoying error?
To use the WSL/Linux gcc and Linux headers/libraries from within VSCode::
Install either the "WSL - Remote" extension or the "Remote Development" extension pack in VSCode.
Either:
From within WSL, cd to your project directory and then start VSCode with code ..
Start VSCode from Windows and click the "Open a Remote Window" button at the bottom left of the screen. It looks like a > < stacked together. Then select "Open Folder in WSL ...". This is also available from the Command Palette (Shift+Ctrl+P) with "Remote WSL - Open Folder in WSL ..."

New to C: Compiling in Visual Studio Code... error: gcc not recognized?

I am very new to coding (trying to teach myself C). I have some experience with MatLab, but I understand it is very different from C. I have Windows 10 with the newest version of Visual Studio Code (VSC) with the Run Code Extension and git extension (not sure what git does, but VSC prompted me to install). I am now familiar with the text editor, but do not know how to compile/run my code (apologies if I'm butchering the terminology, again, a newby). One friend recommended I determine the location in which the desired text file is located, type "gcc filename.c", enter, type "./a.out", and then the program should run. (Said friend has a Mac and I supposed the execution commands are different?) Regardless, I encountered "Run Code" extension on my google adventures and follow the steps I've seen online, but I am still getting the error pictured.
I can see how this would be an especially basic question, but if anyone can offer assistance/advice, I would be extremely grateful!
Thanks, All.
Sandy
P.S. In case the image doesn't load/work for whatever reason, this is the error:
"'gcc' is not recognized as an internal or external command,
operable program or batch file."
Works perfect in Visual Code. You need the following:
C/C++ extension in Visual Code.
msys64 installed in C:\
Add path to msys64 bin folder in environment variable
Instructions:
https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools
Important the msys64 path doesn't contain spaces so don't install it in Program Files.
You can search "Edit system environment variables" from the windows button, press button Environment Variables, and then add it as a System variable "Path". For me its located in
C:\msys64\mingw64\bin
Hey,,,
It will work for you I believe
Blockquote
First: open the link: https://www.msys2.org/
Go to the installation and download the installer .. install the exe file.
search mingw in windows search(windows start)
there is an app named--> MSYS2 MinGW {64/32}-bit
run it as administrator
Found command shell ---> type: pacman -Syu
Will ask you for some installation click on Y
Then again go to the same app MSYS2 MinGW {64/32}-bit and run as admin
and write--> pacman -Ss gcc (in shell that opend after click)
after clicking there will be bunch of things and now you have to care about your windows arch.. if it is 64 bit then write---> pacman -S mingw-w64-x86_64-gcc (and if its 32 you will find something like that where 64 will replaced by 32 in bunch of commands that are showing in your shell)
after executing this command gcc will be installed in your system to check write: gcc --version || g++ --version
After that to install the debugger write pacman -S mingw-w64-x86_64-gdb
to check write: gdb --version
**Every thing got installed in your system now find the mingW file or mysys2 file on C drive(whereever you r mingW file got saved) go the the minGW 64 || 32 accroding to your operating system there is a bin folder click on that and copy the path inside the bin folder and save it in environment variables path **
Blockquote
Enjoy vs code
My recommendation
You are on Windows right? So you can just install Visual Studio IDE (follow this tutorial). Which is better than vs code. This tutorial is for C++ but it works for C as well. Because C++ uses the same compiler as C but with some more things(simple explanation).
The solution for your problem
You are getting the massage 'gcc' is not recognized as an internal or external command, operable program or batch file because you do not have the gcc compiler installed on your computer. But if you want to install it, you can follow this tutorial. But I highly recommend you use Visual Studio IDE which I mentioned above.
Type gcc --version in the command prompt to check whether the C compiler is installed in your machine.
If it is installed then try adding gcc to the environment variables using this link:
https://www.youtube.com/watch?v=qLh84CmdBJ0
If it is not installed then install it using instructions using this link:
https://www.guru99.com/c-gcc-install.html
and then add it to the environment variables using the link above.
If it is installed and not recognized by VSCode then try to run VSCode from CMD by typing code in CMD.

How do I add the basic Cygwin compiler directories to the path on Windows 10 to enable Netbeans IDE to find the tools collection?

I'm trying to learn C as new to programming. I have a Windows 10 machine and have installed NetBeans 8.2 C/C++ version.
I am trying to add the correct Cygwin compiler directory to the right path so everything will run smoothly.
I have completed everything below but point 4 in bold.
The instructions below are from :https://netbeans.org/community/releases/80/cpp-setup-instructions.html#compilers_windows
which teaches you how to install the basic Cygwin GNU gcc and g++ compilers, make and the gdb debugger.I won't be needing anything more than that to learn basic C.
My Environmental Variables look like:
enter image description here
When I click paths on Environmental Variables I have a whole list of paths and I don't know how to 'Add the path to the cygwin-directory\bin directory to the Path variable' in point 4 below.
Please, how do I do this and to which path or am I adding a whole new path?
Any help is most appreciated.
My list of path looks like:
enter image description here
' To install the GNU gcc and g++ compilers, make, and gdb debugger from cygwin.com:
1.Refer to the Cygwin User's Guide for complete information about installing and using Cygwin.
2.Download the Cygwin setup-x86.exe (32-bit installation) or setup-x86_64.exe (64-bit installation) program by clicking Install Cygwin in the left navigation bar, or by clicking the direct setup-x86.exe or setup-x86_64.exe link.
Note: The bitness of Windows OS, Java, and NetBeans IDE installed on your machine must match. For example, if you are running the 64-bit version of Windows operating system, 64-bit Java and 64-bit Cygwin (that is setup-x86_64.exe) are required to be installed. See issue 234221 for details.
Run the downloaded Cygwin installer. Accept the defaults until you reach the Select Your Internet Connection page. Select the option on this page that is best for you. Click Next.
On the Choose Download Site page, choose a download site you think might be relatively close to you. Click Next.
On the Select Packages page you select the packages to download. Click the + next to Devel to expand the development tools category. You may want to resize the window so you can see more of it at one time.
Select each package you want to download by clicking the Skip label next to it, which reveals the version number of the package to download. At a minimum, select •gcc-core: C compiler
•gcc-g++: C++ compiler
•gdb: The GNU Debugger
•make: the GNU version of the 'make' utility
Packages that are required by the packages you select are automatically selected as well.
7.Click Next to connect to the download site and download the packages you selected, and click Finish when the installation is complete.
Now add the Cygwin compiler directory to your path to enable NetBeans IDE to find the tools collection:
1.Open the Control Panel:
- On Windows XP select Start > Settings > Control Panel and double-click System.
- On Windows 7, type var in the Start menu's search box to quickly find a link to Edit the system environment variables.
2.Select the Advanced tab and click Environment Variables.
3.In the System Variables panel of the Environment Variables dialog, select the Path variable and click Edit.
**4.**Add the path to the cygwin-directory\bin directory to the Path variable, and click OK. By default, cygwin-directory is C:\cygwin (for 32 bit Cygwin distribution) or C:\cygwin64 (for 64 bit Cygwin distribution). Directory names must be separated with a semicolon. Your edited path should look something like %SystemRoot%\system32;%SystemRoot%;C:\Program Files\QuickTime\QTSystem;C:\cygwin\bin
5.Click OK in the Environment Variables dialog and the System Properties dialog.
6.See Verifying the Installation to verify that the tools were installed correctly for the NetBeans IDE.'

Eclipse C/C++ project on Bash on Ubuntu on Windows

I've installed Eclipse Neon (v4.6). Also, I have "Bash on Ubuntu on Windows" (Sept '16). I installed gcc and gdb for compiling and debugging in C. I tested them on terminal and they're running.
I'm trying to use Eclipse to create a new C project but in the compiler selection stage it doesnt give me the option to use the "Bash on Ubuntu on Windows" compiler.
Is there any way to solve my problem?
Because Bash/WSL is pretty new and the ability to correctly invoke Linux commands from outside Bash (using bash.exe -c ...) is not well understood by many dev tools (yet), you may have to do some work to define custom tasks/actions to call the necessary bash.exe -c "gcc ..." commands that you want to invoke.
However, you should absolutely be able to write/configure a makefile (or, perhaps even better, a CMake file) which can switch paths to lib/include/tools/etc. based on environment and then build smoothly on Windows or in Linux.
This very scenario has sparked an idea for a cool blog post that I'll work on and publish to our blog https://blogs.msdn.microsoft.com/commandline in the next week or two :)
HTH.
I think the best way to use the wsl for programming in C/C++ is like Microsoft does it. Visual Studio use ssh to connect to linux environment for "C++ for Linux Development".
So, in our case we can set up openssh server on wsl, connect to localhost from your IDE and start remote project.
Eclipse and NetBeans supports remote projects.
Clions I think not.
Here are Microsoft's instruction on how to configure Visual Studio
and wsl:
https://blogs.msdn.microsoft.com/vcblog/2017/02/08/targeting-windows-subsystem-for-linux-from-visual-studio/
May 2017
We use Eclipse and a makefile project. I configured Eclipse by adding an "external builder" - and use the following script:
-c "cd `echo '${project_loc}' | sed -e 's/C:/\/mnt\/c/g' -e 's/\\\\/\//g'` && make -f path_to_makefile/makefile
The "cd" and sed trick is to convert from Eclipse "C:\" to Windows Subsystem for Linux "/mnt/c/" and replace "\" with "/"
Make now executes in the project location as defined by ${project_loc}
I still have not figured out how to execute gdb on Linux. But at least compile+link (and execute unit tests as defined in my makefile) is now leveraging the full speed of the native Ubuntu toolchain...
I have some better way...
You can add new user terminal and give "Ubuntu.exe" location in eclipse under Local terminal setup as shown in screen shot.
in my case directory is ...
C:\Users\MyuserName\AppData\Local\Microsoft\WindowsApps\CanonicalGroupLimited.Ubuntu16.04onWindows_79rhkp1fndgsc
if eclipse not able to select ubuntu16.4.exe, then write manually in path.
as shown in image.
Now just click on Apply and close. Open terminal (Ctrl+Alt+Shift+T) and select Ubuntu terminal.
Now, Navigate to source directory through terminal and compile you project. Enjoy...
Initially I followed espenalb's advice, but it didn't parse my build output correctly: double-clicking on lines didn't open the file, nor go to the line with the error.
I ended up changing the built-in CDT builder (instead of adding an external builder). I changed the build command to be the following (alex is my username):
bash.exe -c make 2>&1 | sed -e 's/\\/home\\/alex/C:\\\\Users\\\\alex/g' -e 's/\\//\\\\/g'
This way, the make output is converted from paths with "/home/alex" to the same path under "c:\users\alex". This fixes the parsing issue.
I also had an issue with eclipse replacing the build output with "Build not configured correctly" - I fixed it by disabling the "Scanner Configuration Builder" in the "Builders" submenu of the project properties (it's a C Makefile project). Also, need to remove targets "all" and "clean" from default build command.
Yet another variation. I managed to build with the external builder command set to
bash.exe -c "cd '${project_loc}' && cd directory_where_the_Makefile_is && make -j8"

WinAVR and native Windows console apps

I'm not that experienced with C, but I've been happily hacking firmware on some hobby projects using WinAVR. I'm visually impaired so I prefer using make files and the command line, instead of a graphically confusing IDE.
Sometimes I want to thrash out an algorithm at the Windows console prompt, with a few printf statements to show me what's happening. But I don't want to install a native Windows variant of GCC and mess up my working WinAVR installation.
What's the best way to proceed?
i think http://www.cygwin.com/ would be a great choice.. you can install cygwin and then install gcc install cygwin. you can have all the unix tools if you want

Resources