How to configure msys2 in codeblocks? - codeblocks

How to configure codeblocks compiler and debugger with msys2 ?
I found an answer related here, but I don't find very usefull as I use windows 7, instead linux ;)
What I want to achive is integrating esp-idf embedded system in codeblocks.
Is this even possible ? Anyone ?

Install CodeBlocks 20.03 without the compiler (installer: codeblocks-20.03-setup.exe, about 37.5 Mb)
Download and install Msys2 by following the instructions on the homepage
Install the mingw-w64 toolchain (open the Msys64 shell and run the command: pacman -S git mingw-w64-x86_64-cmake make mingw-w64-x86_64-toolchain)
Now you need to configure the compiler in CodeBlocks.
Go to Settings -> Compiler...
Click on Toolchain executables tab and browse for mingw64 folder (without bin).
Edit the executable file names as gcc.exe, g++.exe and g++.exe
Click Ok to confirm
Go to Settings -> Debugger... and configure gdb.exe as default debugger (browse for the gdb.exe file into the bin directory)
Now the GCC compiler and the GDB debugger are configured.
You can use pacman from the Msys2 shell, to download and install or uninstall a lot of packages.
I don't know esp-idf but it seems to me that this sdk is not distributed as a msys2 package.

Related

Visual code says compiler is not recognized

I downloaded visual code 1.60.2 for windows 7 . My pc has 32 bit operating system.When i downloaded vs code and ran the code it shows up"'gcc' is not recognized as internal or external command".
Please tell me what should i do.
You have to install a MINGW Environment in order to use gcc with Windows.
Steps:
Install C/C++ extension for VS Code
Install Mingw-w64
Add mingw bin path to your PATH variable in windows.
If you have already installed the extension and mingw, you forgot to add it to the path variable. Validate this with opening a Commandline or Powershell an call:
g++ --version
Here is a detailed guide how to do this: Using GCC with MinGW

Step by step instruction to install Rust and Cargo for mingw with Msys2?

I tried to install Rust on Cygwin but failed to be able link with mingw. Now I am trying to install it with Msys2. I already installed Msys2 and Mingw. I tried to follow this wiki page but I got lost at number 2:
Download and install Rust+Cargo using the installer but be sure to disable the Linker and platform libraries option.
Is it referring to the "rustup-init.exe" on the install page? Should I double click to run this file or run it from Msys2? I tried to run from Msys2 and got the options:
1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
I don't know what to do next.
The Using Rust on Windows page you linked to dates from before rustup replaced the installer as the default option to install Rust. Installers are still available, but you should use rustup if possible, because it makes it easy to update and to use multiple toolchains at once (e.g. stable, beta and nightly). If you must use the installer, just select the x86_64-pc-windows-gnu installer and follow the step from the Using Rust on Windows page. If you're using rustup, read on.
By default, rustup on Windows installs the compiler and tools targeting the MSVC toolchain, rather than the GNU/MinGW-w64 toolchain. At the initial menu, select 2) Customize installation. When asked for a host triple, enter x86_64-pc-windows-gnu. Then make a choice for the other questions, then proceed with the installation.
Note: If rustup is already installed, then rerunning rustup-init won't actually install the requested toolchain. Instead, run rustup toolchain install stable-x86_64-pc-windows-gnu if you already have the MSVC-based toolchain. Then run rustup default stable-x86_64-pc-windows-gnu to set the GNU-based toolchain as the default.
Rustup will install the MinGW linker and platform libraries automatically (as part of the rust-mingw component) and refuses to let you remove them. If you prefer to use the MinGW linker and libraries you installed with MSYS2, you'll need to create a .cargo/config file (either in your profile directory, i.e. C:\Users\you\.cargo\config, or in your project's directory if this configuration is specific to a project). The contents of that file might look like this:
[target.x86_64-pc-windows-gnu]
linker = "C:\\msys2\\mingw64\\bin\\gcc.exe"
ar = "C:\\msys2\\mingw64\\bin\\ar.exe"
Rustup will modify the PATH environment variable unless you told it not to. However, MSYS2 resets PATH by default when you launch, so when you try to invoke cargo or rustc from your MSYS2 shell, it might not find it. You'll need to edit your .profile/.bash_profile script to set the PATH correctly (you need to prepend /c/Users/yourname/.cargo/bin: to PATH).
my problem resolved by following way
Run rustup toolchain install stable-x86_64-pc-windows-gnu
Second open .rustup folder
Open settings.toml file
Change first line with: default_toolchain = "stable-x86_64-pc-windows-gnu"
done!
I wrote a complete guide on how to
install Rust on windows with Visual Studio Code and MSYS2 MinGW
on the page found here:
https://stackoverflow.com/a/68835925/4230643

msys2 doesn't find mingw64

I downloaded:
https://mingw-w64.org/doku.php/download/mingw-builds
https://mingw-w64.org/doku.php/download/msys2
and installed them under C:/development/msys64. Under this folder I find the msys2.exe and the mingw64 folder, which in turn contains the bin one with all the mingw executable.
I added C:/development/msys64/mingw64/bin folder to the PATH env var.
In fact from a Windows prompt I can invoke the gcc - for example. Instead inside the msys2 shell I cannot find them. I mean, they are in /mingw64/bin but they are not available at prompt.
I'm sure I missed some steps!
Method to switch from MinGW-w32 to MinGW-w64
Download the executable file of MinGW-w64 Refer the EDIT
(Executable file link may change for future releases, this is for Version 8.1.0, Kindly cross verify the latest version before installing from this link)
Installation Process (In Settings):
Version: PICK LATEST
Architecture: x86_64
Threads: posix
Exception: seh
If anyone is trying to add MinGW-w64 as a PATH variable and is not able to find the gdb.exe in C:\msys64\mingw64\bin, try looking for it in the Program files.
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin
The gdb.exe and other files are located in this directory.
EDIT:
After making some changes in the launch.json file in VSCode, the MinGW-w64 GDB debugger started giving errors because there was 2 versions of MinGW in different folders i.e, MINGW and mingw64!
It is essential that the installation path does not contain any spaces
(i.e., space in "Program Files"), this will create conflicts later.
STEPS:
1. Uninstalled all the versions of GCC that was installed in the PC - Cygwin, MSYS2(32 bit) and mingw64(64 bit) and installed the MinGW-w64 again, this time using the MSYS2.
Please start afresh, if debugger is giving errors and if versions are clashing!
2. Download the MSYS2 installer from this link.
Install process is simple, follow the steps mentioned in the website!
It is essential that the installation path does not contain any spaces. Therefore, we cannot install MinGW-w64 in Program Files.
3. After Installation is complete: Open MSYS2 terminal (pink icon).
Update the package database and base packages using:
pacman -Syu
After this, Update rest of the base packages using:
pacman -Su
4. Now switch over to MSYS2 MinGW 64-bit terminal (blue icon).
To install gcc and g++ for C and C++.
For 64 bit:
pacman -S mingw-w64-x86_64-gcc
To install debugger (gdb).
For 64 bit:
pacman -S mingw-w64-x86_64-gdb
5. Now you're all SET!
Check versions:
gcc --version
g++ --version
gdb --version
6. Finally, remove the old environment variables if any are left and add the new environment variable to the PATH!
BEFORE DEBUGGING FILES IN VSCode, MAKE SURE TO ADD -g tag while building, otherwise breakpoints will be ignored by the debugger!
Footnote:
It's very important to keep all the versions in one folder, if folders are different, then life will get tough later!
MSYS2 has packages for its own GCC toolchains and you would probably be better off using those toolchains instead of downloading a different one. For example, to use a 64-bit MinGW GCC, you would have to run pacman -S x86_64-w64-mingw32-toolchain and then make sure you are starting MSYS2 using the "MinGW-w64 64-bit Shell" shortcut (or something like that) so that /mingw64/bin is on your PATH.
Also, MSYS2 does not respect your system or user environment variables; it uses its own PATH by default.

CLion Installation: Cmake compilers not found, GDB not found

I'm switching from VS to CLion and they said I needed to install Cygwin and CMake. I then installed both of them. I tried use bundled, but CLion still gives me these errors make: not found C Compiler: not found C++ Compiler: not found GDB: not found.
I have installed CMake under the path C:\Users\Gaga\Downloads\cmake-3.4.1 but I don't see a cmake.exe, the closest thing is cmake.cxx.
Without these I'm not able to compile anything, please help
In the "Use specified" field I put C:\cygwin64\bin\cmake.exe your path may be different. Just ensure you have CMake, Make, gdb and gcc installed already in Cygwin (using the Cygwin setup.exe not via the CMake website) but I believe Clion checks if you have them installed after inputting the path.
The workaround would be to use MinGW. If you download it from the website it should come with cmake, and take care of the errors.
http://mingw.org/
When extract it and go to the installer you should check something like gcc and then from the top left corner something like 'install packages'
Be sure not to accidentally download the source, which I did, which would lead you toward this error: CLion: CMake Errors Source directory does not exist
Edit: So over a year later, I've learned a little more about Cygwin and mingw beyond what the internet says. CLion needs a "Unix-like" environment. If you use CLion on MacOS or a Linux it's already Unix based. Anything that is "POSIX" compliant will work. CygWin is a terminal emulator for windows where Unix commands like mkdir work. MinGW is something similar but not posix. Comes with GCC tho. I'm still a noob.
I had the same problem.
While installing cygwin, need to select the packages of cmake, gcc, gdb
Got the answer from the below link.
Select Packages while installing cygwin
After the installation go to the configuration page and select the cygwin directory. CLion will identify the configuration and you are done...

GMP on visual studio c++

I'm new for the c++ programming. I installed OpenSSL for my visual studio. I would like to install GMP for visual studio. How should I do that? There is no file such as gmp.exe. I dont know how to install this. Any help would be appreciated.
It isn't that hard to install GMP on windows.
First, download the GMP tar file. You have to install cygwin on windows with gcc, make and m4.
You can then run linux command using cygwin. Decompress the tar file, then (RECOMMEND to check out the INSTALL file).
Do ./configure, if you need anything special like running c++ gmp code, you have to add flags.
Do./configure --help to check it out.
Then run make, make check, and finally run make install.
You will have to add the path back to your project properties. Enjoy !

Resources