Rust installation on Windows - windows

I was trying to get Rust to work on my Windows box. I followed the instructions, however when I tried hello world program, it spits the below. It looks like it has not been able to link up to gcc.. and I have gcc out there. Could someone help me figure out what is the issue here?
$ rustc foo.rs
error: linking with `gcc` failed: exit code: 1
note: gcc arguments: '-m32' '-LC:\Program Files (x86)\Rust\bin\rustlib\i686-pc-m
ingw32\lib' '-o' 'foo' 'foo.o' '-shared-libgcc' '-LC:\MinGW\msys\1.0\home\ENwank
wo\.rust' '-LC:\MinGW\msys\1.0\home\ENwankwo' 'C:\Program Files (x86)\Rust\bin\r
ustlib\i686-pc-mingw32\lib\libstd-3e5aeb83-0.9.rlib' 'C:\Program Files (x86)\Rus
t\bin\rustlib\i686-pc-mingw32\lib\libgreen-83b1c0e5-0.9.rlib' 'C:\Program Files
(x86)\Rust\bin\rustlib\i686-pc-mingw32\lib\librustuv-2ba3695a-0.9.rlib' '-lws2_3
2' '-lpsapi' '-liphlpapi' '-lmorestack'
note: gcc: fatal error: -fuse-linker-plugin, but liblto_plugin-0.dll not found
compilation terminated.
error: aborting due to previous error
task 'rustc' failed at 'explicit failure', C:\bot\slave\dist2-win\build\src\libs
yntax\diagnostic.rs:75
task '<main>' failed at 'explicit failure', C:\bot\slave\dist2-win\build\src\lib
rustc\lib.rs:453

This is how to install Rust on windows with Visual Studio Code and optionally MSYS2 MinGW
You can Instal Rust without installing "Microsoft C++ Build Tools". You can also use Rust with the gcc or clang tools from the MSYS2 suite.
I didn't want to install Rust on Windows with the required "Microsoft C++ Build Tools" because this would need too much disk space.
To get Microsoft C++ Build Tools on Windows you need to download a full Windows SDK which is very large (I think more than 4GB).
You can run and debug Rust programs without installing MSYS2.
If you want to use the gcc or clang compilers that are included in MSYS2 (you will need to install them in a separate step from the MSYS2 installation, using the version of the pacman package manager from MSYS2), then you can install MSYS2.
(MSYS2 also allows you build very easily, C++ programs inside Visual Studio Code with the C++ extensions installed, using the gcc or clang compilers).
The MSYS2 installation version needs 1.61 GB for MSYS2 ( The tools installed using mingw-w64-x86_64-toolchain occupy 1083.49 MiB of disk space out of the 1.61 for the total MSYS2 suite).
Rust installs about 1.46 GB of files - mostly in the "C:\Users\user\.rustup" folder when using the parameter "x86_64-pc-windows-gnu" (for a MSYS MinGW install).
Rust takes up 900 MB after installation, when using "x86_64-pc-windows-msvc" (for a "Microsoft C++ Build Tools" install).
For a better Rust experience inside VS Code it is recommended to install the rust-analyzer extension Online from the VS Code Marketplace, or instead of it, the Rust plugin from [Link1] below, at the bottom of the post.
All you have to do is:
Install Visual Studio Code
(Optional - Install MSYS2)
Install Rust
Install Pyton if you don't have it
Add the required folders to the PATH variable
Install rust-analyzer and CodellDB extensions inside VS Code
At the end of this guide you should be able to run and debug rust programs inside Visual Studio Code.
MSYS2 is optional, you can install it if you want to use the gcc or clang from the suite - after creating the cargo config file, the cargo build and cargo run commands will use msys64\mingw64\bin\clang++.exe (by default if both compilers are installed, or ..\msys64\mingw64\bin\gcc.exe if you set it up to do this).
Just follow the installation from Part 1 - below.
(This part is just for reference - it lists the files and folders required for setup and how I chose the installation directories - )
I installed the programs inside these folders:
D:\Applications\msys64
D:\Applications\VSCode
rustup-init.exe installs the .cargo folder in the default location:
C:\Users\user\.cargo
( The settings files for VS Code are created and edited inside the Visual Studio Code editor, you don't need to open the files form windows explorer:
C:\Users\user\AppData\Roaming\Code\User\settings.json
C:\Users\user\AppData\Roaming\Code\User\keybindings.json
)
Part 1 - Installation Steps with Details:
I will use the code needed to run the installation programs inside "quotes" - remove the quotes when you run the commands.
For example: "pacman -Syu" - remove the quotes and just run pacman -Syu .
Change the paths in the tutorial, for your installations.
The programs needed are VS Code, MSYS2 (MSYS2 has files/tools from MinGW), the rust-analyzer extension for VS Code for code completion and the CodeLLDB extension (with the author Vadim Chugunov) for debugging.
Make sure to have the Windows Firewall setup to allow connections out for MSYS2, VS Code, the Rust installer - rustup-init.exe (maybe rustup later on - during this tutorial you don't need it) and D:\Applications\msys64\usr\bin\pacman.exe. This will allow the programs to download necessary files for components or plugins.
a)
Download Visual Studio Code portable version for Windows from filehorse.com and extract the files (or install it any way you like).
Open VS Code and disable the 2 telemetry options from the settings:
Click on Edit > Preferences > Settings, type telemetry in the input box and disble the 2 telemetry options (or press the key combo: Ctrl + Shift + P, type open settings and press Enter to open the 'settings.json' file)
this will put inside the "settings.json" file this code, between the main open and close curly braces:
"telemetry.enableCrashReporter": false,
"telemetry.enableTelemetry": false
Good fonts to use inside VS Code are: Fira Code, Consolas, DejaVu Sans Mono, Droid Sans Mono Slashed, Inconsolata-g, Bitstream Vera Sans Mono , Lucida Console, maybe Menlo Regular (was used in MacOS), Meslo LG DZ.
Fonts like 'Fira Code' have font ligatures present inside the font. 'Fire Code' doesn't have traditional font ligatures for example ft is not connected, but has ligatures specific for coding, for example the look of these character combinations are changed and usually look better with ligatures enabled: fl , -> , <= , >= . See the image below the post for an image with font ligatures on vs off.
To enable font ligatures, open the Preferences for Visual Studio Code, search for ligatures in the search box, and enable the setting: 'Editor:Font Ligatures' .
You can change the default user data directory from:
"C:\Users\user\AppData\Roaming\Code" to your desired location, e.g. :
"D:\Applications\VSCode\UserData\Code"
by creating a shortcut for VSCode with the parameter --user-data-dir, that you'll use to launch VS Code.
To do this create a shortcut for VSCode with the setting for Target: D:\Applications\VSCode\Code.exe --user-data-dir "D:\Applications\VSCode\UserData\Code"
b) This step is Optional, follow it only if you want to use gcc or clang from MSYS2:
You can run Rust programs and compile them in Visual Studio Code without installing MSYS2. Install MSYS2 only if you want to use its gcc or clang compiler.
Optional - Install MSYS2 - this is about 1.61 GB.
Download MSYS2 and follow the installation instructions - I will mention the most important steps:
Install MSYS2 and keep the checkbox selected: "run MSYS2 64bit" at the end of the installation.
Run pacman -Syu in the console that appears after the installation. This is the MSYS2 shell.
!!! For the next step, be careful an choose the right shortcut Don't choose the MinGW one, so
run the shortcut named "MSYS2 MSYS" from Start menu (it is "D:\Applications\msys64\msys2_shell.cmd -msys"). This is the MSYS2 shell.
Inside the shell run pacman -Su .
The next step is to download the programs needed to build the programs written in Rust, for the Windows Platform:
From the start menu run "MSYS2 MinGW 64-bit" (it is "D:\Applications\msys64\msys2_shell.cmd -mingw64"). This is for MinGW and it has a different parameter from the shortcut used above.
Run pacman -S mingw-w64-x86_64-toolchain.
Press Enter, Enter and type 'y' during the installation process.
( The guide on the msys2.org page said to also install some packages using the option '--needed base-devel' by runnig the command "pacman -S --needed base-devel mingw-w64-x86_64-toolchain", but I don't think they are needed here.
If you want, you can install single tools and their dependencies from the list of tools installed by the command "--needed base-devel", by selecting their corresponding number during the installation, for example you can just install make and not the rest of the tools present in the "--needed base-devel" package.
The simple rust "hello world" program that I wrote in rust using VS Code and the rustc and cargo tools/programs ran well without installing the "--needed base-devel" files.
The --needed base-devel files are not needed to run and debug simple Rust programs,but you can install them if you want.
To use the gcc or clang linker and compiler from MSYS2 you have to create the C:\Users\user\.cargo\config file:
To make the cargo use clang++.exe , add these lines to the C:\Users\user\.cargo\config file:
[target.x86_64-pc-windows-gnu]
linker = "D:\\Applications\\msys64\\mingw64\\bin\\clang++.exe"
ar = "D:\\Applications\\msys64\\mingw64\\bin\\llvm-ar.exe"
If you want to change the linker to gcc, create the C:\Users\user\.cargo\config file that contains the lines:
[target.x86_64-pc-windows-gnu]
linker = "D:\\Applications\\msys64\\mingw64\\bin\\gcc.exe"
ar = "D:\\Applications\\msys64\\mingw64\\bin\\ar.exe"
(clang++.exe is the same file as clang.exe from the same directory.)
I got everything installed and running well - I could run the programs and debug them using gcc or clang.
)
c)
Install Rust for Windows
Download the installer: rustup-init.exe from rust-lang.org
The browser should recognize that you ar using Windows and give you the link to "DOWNLOAD RUSTUP-INIT.EXE (64-BIT)" , that is:
[...]static.rust-lang.org/rustup/dist/x86_64-pc-windows-msvc/rustup-init.exe
Run rustup-init.exe . It is better to launch a console with cmd.exe and launch rustup-init.exe from there.
choose "Continue? (y/N)" by typing y and hitting the Enter key.
choose "2) Customize installation" using the keyboard.
paste or type the option: x86_64-pc-windows-gnu .
Press enter for the rest of the options.
Finally type "1" as input in the console, then press Enter, to choose the option "1 to proceed" with the Current installation Options.
There might be problems if you had rustup already installed.
If you already have rustup installed follow the indications on the guide at Source 1 Link at the bottom of the page with the step-by-step-instruction-to-install-rust-and-cargo-for-mingw-with-msys2 :
This is a quote from that post:
"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."
d) Add the folders to the PATH
Add the folders that have useful programs from rust and msys2 to the Windows system PATH variable:
Adding the folders to the system PATH variable will allow VS Conde console, which defaults to PowerShell (you can change it to Command Prompt or other shell if you want), to recognize the commands:
cargo, rustc, etc.
This will make running and debugging rust programs in VS Code with the rust-analyzer and CodeLLDB extensions easy because you don't have to configure anything else.
To add the folders to the PATH use the System Properties window:
Right click on "My Computer" and select "properties"
Click on Advanced System Settings
In the Advanced tab, click on "Environment Variables"
under 'User variables for user' click on the PATH Variable and add the locations of your cargo\bin folder and mingw64\bin folder, (plus \msys64):
;C:\Users\user\.cargo\bin;D:\Applications\msys64;D:\Applications\msys64\mingw64\bin
This will add the folders "C:\Users\user\.cargo\bin", "D:\Applications\msys64", "D:\Applications\msys64\mingw64\bin" to the PATH variable. (stackoverflow is bad at formatting \. backslash followed by a dot - you have to use another backslash as an escape character)
To test that the PATH variable is updated open a NEW Command Prompt or PowerShell window, and in this window run cargo --version or gcc --version (if you installed MSYS2 and gcc.exe) or rustc --version inside a 'Command Prompt' window and inside a PowerShell Window.
If the commands are not found, restart your computer so that Windows can update the PATH variable. For me the change worked without having to restart, I just had to open a new shell window.
e) Install the Rust extensions for VS Code
rust-analyzer and CodeLLDB require Python to be installed.
Install Python 3.6.3, for example, and select to add it to the path during installation.
From the VS Code Marketplace install the needed extensions.
Open VS Code, click on the Extensions button on the right toolbar, and search and install the extensions:
rust-analyzer - (publisher: matklad) ;
CodeLLDB (publisher: Vadim Chugunov);
( I didn't have to do this next step so you shouldn't either - if rust-analyzer doesn't load/run properly, you may need to install the rust source code.
Using the 'Command Prompt' run: rustup component add rust-src to install the rust Source Code.
I didn't have to install it, the rust-analyzer worked well [ by the way, the VS Code could connect to the internet during testing].
)
[While running Visual Studio Code you may get a message telling you to install .Net Framework 4.5.2. Download and install the Offline version if the online version fails to install. (On Windows 7 without some updates, you may have to download and install the certificate: MicRooCerAut2011_2011_03_22.crt, and install some windows updates: Windows6.1-KB2533623-x64, windows6.1-kb2813430-x64, and maybe Windows6.1-KB4019990-x64 ) ]
Part 2 - Running and Debugging Rust programs with VS Code
Running and compiling in Rust with VS Code and Msys2:
After adding the folders to the PATH and installing the extensions, you basically need to run:
cargo init
cargo run - to run the program.
press the F5 key, or click the debug button to debug the code.
First you need to:
Create a folder for your Rust app.
Open the folder inside VS Code.
Press Ctrl+{`} to open the terminal panel.
The default shell will be 'PowerShell'.
You can select the 'Command prompt' shell from the Terminal pane using the down arrow on the left, that is near the plus button and x button.
Or you can set VS Code to use 'Command Prompt' as the default shell by adding the lines to the 'settings.json' file - the main Visual Studio Settings file.
"terminal.integrated.defaultProfile.windows": "Command Prompt",
You can use PowerShell or 'Command Prompt', they both work fine.
Run cargo init inside the terminal to create the project files.
Edit the main.rs file if you want. It is located inside 'app folder'\src\main.rs
Run cargo run inside the terminal
If you have rust-analyzer installed, the extension puts 2 buttons as popups on top of the main() function.
They are named 'Run' and 'Debug' and if clicked they do what their names say.
To debug, put a breakpoint inside your main.rs file and hit F5 (the menu entry Run > Start Debugging) or click the Debug button on top of the main() function placed there by the rust-analyzer extension if you have it installed.
If you click the debug button you don't have to create a launch.json config file.
If you hit the F5 key or click the menu entry Run > Start Debugging, a launch.json file will be added to your folder.
Just click Yes in the message box to auto generate the launch.json file.
Then hit the F5 key again to start debugging.
Now you can step through your code during the debugging process.
Link 1: https://marketplace.visualstudio.com/items?itemName=rust-lang.rust
Link to Font Ligatures example - Image for the font 'Fira Code':
Image Link: Coding font with font ligatures

This question is old, but in the mean time a lot has changed.
The easiest way to install on Windows is to go to the Rust installation page and download and run rustup-init.exe. It installs rustc, rustup and similar tools. It just works™.

Related

nvim_treesitter installation on windows

bad English (sorry).
I'm trying to get nvim_treesitter to work on my windows machine, on my Linux one it worked great but now when I try on windows the :checkhealth nvim_treesitter gives:
health#nvim_treesitter#check
Installation
ERROR: tree-sitter executable not found
OK: git executable found.
ERROR: cc executable not found.
ADVICE:
Check that either gcc or clang is in your $PATH
Parser/Features H L F I
Legend: H[ighlight], L[ocals], F[olds], I[ndents]
*) multiple parsers found, only one will be used
x) errors found in the query, try to run :TSUpdate {lang}
and I'm totally new to this thing, any advice would help:)
The main issue from my perspective is "ERROR: cc executable not found.". It means nvim_treesitter couldn't find any compiler on your machine, and so no parsers could be compiled and installed when you issue ":TSInstall {some_parser_name}" commands.
If you have Visual Studio installed (since nvim gets compiled by VS 2017, it's fine to have 2017 or 2019 studio, I guess), try this:
Run "x64 Native Tools Command Prompt for VS 201x" if you've downloaded nvim-win64 release package or "x86 Native Tools Command Prompt for VS 201x" otherwise (nvim-win32 package)
Run nvim in this command prompt (i.e. nvim-qt GUI)
Install any parsers you want, let's say ":TSInstall c". Output should look like this:
Downloading...
Compiling...
Treesitter parser for c has been installed.
Optionally run :checkhealth nvim_treesitter again to see if everything is fine
Thereafter you can run nvim in any console, not via VS Tools one only (still use it to install or update parsers though).
Please also see https://github.com/nvim-treesitter/nvim-treesitter/wiki/Windows-support for various instructions.
For the Error: tree-sitter: You can checkout creating parsers and follow the description or you download the windows binary of the binary files and put it into a directory on your PATH.
For the Error: cc: You need to install gcc
Try to apply this vsc tutorial from Prerequisites №3
I had the same issue. It helped me.
Ok, here's what I've done and what helped me:
Go to https://www.msys2.org and follow ALL of the installation steps that are described there:
Download and install
Run pacman -Syu comman
Run pacman -S --needed base-devel mingw-w64-x86_64-toolchain and choose mingw-w64-x86_64-gcc there.
After everything is installed, put into your PATH Environment Variable the path to MinGW64\bin folder (if you installed everything to the default folder it will be c:\msys64\mingw64\bin)
And you are good to go! Now open nvim and run
:TSInstall <yourlang>
For example, :TSInstall php
PS: you can get the list of available languages using :TSInstallInfo

Windows IDE for Haskell

I need to setup a simple and compelling dev environment for small proyects written in Haskell in Windows machines for freshmen.
I have tried several ways to integrate Haskell into VSCode in Windows with no success.
I had a nice setup a few years ago, but I´m finding problems with dependencies recreating that environment:
Editor: Atom
Global binaries build using: stack with ghc-mod hlint stylish-haskell
Atom plugins: language-haskell, ide-haskell, ide-haskell-repl, haskell-ghc-mod
It seems that the "cool" way right now is Language Server Protocol + VScode. ghc-mod seems not to be mantained anymore, Intero has reached EOL, HEI is merging with another project... Having a stable and updated dev environment looks like a moving target.
So, the question is: does anyone have reproducible step-by-step instructions for having VSCode working with Haskell in Windows?
I will test any suggestion in a fresh Windows 10 64bits VM and report the results.
Note: VSCode + Docker container is not an option. Most of the student´s machines have 4GB RAM.
Thanks in advance.
There's a tool called ghcid (not to be confused with ghcide) that, while nowhere near a full-blown IDE, is pretty robust and provides some niceties like re-compiling on save and showing compile errors. It doesn't support go-to-definition though. It has a VSCode plugin.
Here's a possible way of setting up things in Windows:
Download the GHC 8.8.3 binaries for Windows from here.
Download the cabal-install 3.0.0.0 binaries for Windows from here.
Decompress them in some folder.
Add entries to your PATH environment variable so that it has access to the /bin folder of the GHC installation and to the folder containing the cabal executable.
Open a Powershell console.
Run cabal udpate
Run cabal install --install-method=copy --installdir=somefolder ghcid to install the ghcid executable, where "somefolder" is the destination folder. (If the installation fails, try running the command from a Git Bash or Cygwin terminal as a workaround.) Put the destination folder in PATH.
Open (or restart) VSCode and install the "Haskell Syntax Highlighting" and haskell-ghcid plugins.
Go to an example cabal project, use the Ctrl-Shift-P shortcut, and execute the Start ghcid action. The ghcid terminal will appear.
Example of a ghcid session showing an error:
The haskell-ghcid plugin can read a .ghcid file in the project root containing flags that should be passed to the ghcid command.
Extra instructions to set up code formatting:
Install the ormulu formatter by running cabal install ormolu --install-method=copy --installdir=somefolder. Again, make sure that the destination folder in in PATH.
Open (or restart) VSCode and install the ormulu plugin.
Now the "Format Document" and "Format Selection" actions in VSCode will use ormulu.
Another way of installing GHC and getting to ghcid and ormulu could be by using the stack tool, which handles GHC installation by itself.

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

Can't find file executable in your configured search path for gnc gcc compiler

My problem is that code::blocks error message tells me that it can't find file executable in the search path for gnc gcc compiler. Although, I don't know what that means. Also I typed out some code:
#include <iostream>
using namespace std;
int main(void) {
cout <<"Hello World" <<endl;
return 0;
}
I can't build it or run in code::blocks. What do I need to do?
I went on line but I got some answers that are way over my head. I was able to use code::blocks once before I installed Visual studios express 2013. Visual studios didn't work right either. It kept asking me to repair or uninstall every time I tried to open it. So I deleted it along with code::blocks. Now that I re-installed code::blocks I still can't get to work right.
This problem with compilers is taking up all my time and I can't practice learning programming because I can't get any compiler to work right. I need some help, please.
I'm guessing you've installed Code::Blocks but not installed or set up GCC yet. I'm assuming you're on Windows, based on your comments about Visual Studio; if you're on a different platform, the steps for setting up GCC should be similar but not identical.
First you'll need to download GCC. There are lots and lots of different builds; personally, I use the 64-bit build of TDM-GCC. The setup for this might be a bit more complex than you'd care for, so you can go for the 32-bit version or just grab a preconfigured Code::Blocks/TDM-GCC setup here.
Once your setup is done, go ahead and launch Code::Blocks. You don't need to create a project or write any code yet; we're just here to set stuff up or double-check your setup, depending on how you opted to install GCC.
Go into the Settings menu, then select Global compiler settings in the sidebar, and select the Toolchain executables tab. Make sure the Compiler's installation directory textbox matches the folder you installed GCC into. For me, this is C:\TDM-GCC-64. Your path will vary, and this is completely fine; just make sure the path in the textbox is the same as the path you installed to. Pay careful attention to the warning note Code::Blocks shows: this folder must have a bin subfolder which will contain all the relevant GCC executables. If you look into the folder the textbox shows and there isn't a bin subfolder there, you probably have the wrong installation folder specified.
Now, in that same Toolchain executables screen, go through the individual Program Files boxes one by one and verify that the filenames shown in each are correct. You'll want some variation of the following:
C compiler: gcc.exe (mine shows x86_64-w64-mingw32-gcc.exe)
C++ compiler: g++.exe (mine shows x86_64-w64-mingw32-g++.exe)
Linker for dynamic libs: g++.exe (mine shows x86_64-w64-mingw32-g++.exe)
Linker for static libs: gcc-ar.exe (mine shows x86_64-w64-mingw32-gcc-ar.exe)
Debugger: GDB/CDB debugger: Default
Resource compiler: windres.exe (mine shows windres.exe)
Make program: make.exe (mine shows mingw32-make.exe)
Again, note that all of these files are in the bin subfolder of the folder shown in the Compiler installation folder box - if you can't find these files, you probably have the wrong folder specified. It's okay if the filenames aren't a perfect match, though; different GCC builds might have differently prefixed filenames, as you can see from my setup.
Once you're done with all that, go ahead and click OK. You can restart Code::Blocks if you'd like, just to confirm the changes will stick even if there's a crash (I've had occasional glitches where Code::Blocks will crash and forget any settings changed since the last launch).
Now, you should be all set. Go ahead and try your little section of code again. You'll want int main(void) to be int main(), but everything else looks good. Try building and running it and see what happens. It should run successfully.
Just open your setting->compiler and click on the reset defaults and it will start work.
* How to Download and install CodeBlocks.* ( I have already downloaded )
***How to solve the CodeBlocks environment error.
Go to "Settings"----"Compiler"----"Selected compiler"( GNU GCC Compiler ).
Then, Selected "Toolchain executables".
Now, "( C:\Program Files (x86)\CodeBlocks\MinGW )"
See Video : https://youtu.be/Tb1VnXs60Lg
I had also found this error but I have solved this problem by easy steps. If you want to solve this problem follow these steps:
Step 1: First start code block
Step 2: Go to menu bar and click on the Setting menu
Step 3: After that click on the Compiler option
Step 4: Now, a pop up window will be opened. In this window, select "GNU GCC COMPILER"
Step 5: Now go to the toolchain executables tab and select the compiler installation directory like (C:\Program Files (x86)\CodeBlocks\MinGW\bin)
Step 6: Click on the Ok.
Now you can remove this error by follow these steps. Sometimes you don't need to select bin folder. You need to select only (C:\Program Files (x86)\CodeBlocks\MinGW) this path but some system doesn't work this path. That's why you have to select path from C:/ to bin folder.
Thank you.
For that you need to install binary of GNU GCC compiler, which comes with MinGW package. You can download MinGW( and put it under C:/ ) and later you have to download gnu -c, c++ related Binaries, so select required package and install them(in the MinGW ). Then in the Code::Blocks, go to Setting, Compiler, ToolChain Executable. In that you will find Path, there set C:/MinGW.
Then mentioned error will be vanished.
Uninstall/Remove your current codeblocks compiler.
Install codeblocks using this link that contains GCC compiler files: http://sourceforge.net/projects/codeblocks/files/Binaries/13.12/Windows/codeblocks-13.12mingw-setup-TDM-GCC-481.exe.
Now go to : Settings > Compiler.... > ToolChain Executables Tab
CLICK on Auto-detect button and then click OK button. Now just restart CodeBlocks and start writing your codes and use the Build and run option. It will RUN normally.
Fistly, Code Blocks is not a compiler. It is just an integrated development environment.
So, you must show the path of your compiler at first, (if you dont have a compiler you have to download an install, it is not difficult to find. f.e. GCC is good one.)
If code blocks could not find automatically the path of compiler it is an obligation to show it yourself.
But when you install, probably Code Blocks automatically find your compiler.
Enjoy.
This simple in below solution worked for me.
http://forums.codeblocks.org/index.php?topic=17336.0
I had a similar problem. Please note I'm a total n00b in C++ and IDE's but heres what I did (after some research)
So of course I downloaded the version that came with the compiler and it didn't work. Heres what I did:
1) go to settings in the upper part
2) click compiler
3) choose reset to defaults.
Hopefully this works
I'm a total noob but I reinstalled over the codeblocks giving me these "Can't find file executable in your configured search path for gnc gcc compiler" errors by downloading:
codeblocks-20.03mingw-setup.exe
(IMPORTANT: make sure it has the "mingw" in the file download name, that has the compiler build that is required to compile the code which doesn't automatically comes with the main codeblocks editor software download because codeblocks already assumes you already have another compiler installed on your computer {visual studio 2019 or such}).
Then when I created a new project (console application) and used the defaults to quickly test it out.
It gave me errors.
So I went to Settings > Compiler > Selected Compiler set to: GNU GCC Compiler > Click on the "Tooolchain executables" tab > Click on Auto-Detect > Should say "C:\Progam Files\CodeBlocks\MinGW" > Click OK.
Build and run a simple hello world code.
Should work! If not, look for the "MingGW" in the C:\Program Files\CodeBlocks and select it.
Here's an easy way for Windows users.
Uninstall the existing codeblocks from your system.
Restart system.
Go to http://www.codeblocks.org/downloads/26
Download the codeblocks-16.01mingw-setup.exe file. It includes the GCC/G++ compiler and GDB debugger from TDM-GCC (version 4.9.2, 32 bit, SJLJ).

How to install pkg config in windows?

I am trying to do it, but all I can get is some source code that I don't know how to do deal with I downloaded from http://pkgconfig.freedesktop.org/releases/.
This is a step-by-step procedure to get pkg-config working on Windows, based on my experience, using the info from Oliver Zendel's comment.
I assume here that MinGW was installed to C:\MinGW. There were multiple versions of the packages available, and in each case I just downloaded the latest version.
go to http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/
download the file pkg-config_0.26-1_win32.zip
extract the file bin/pkg-config.exe to C:\MinGW\bin
download the file gettext-runtime_0.18.1.1-2_win32.zip
extract the file bin/intl.dll to C:\MinGW\bin
go to http://ftp.gnome.org/pub/gnome/binaries/win32/glib/2.28
download the file glib_2.28.8-1_win32.zip
extract the file bin/libglib-2.0-0.dll to C:\MinGW\bin
Now CMake will be able to use pkg-config if it is configured to use MinGW.
Get the precompiled binaries from http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/
Download pkg-config and its depend libraries :
pkg-config_0.26-1_win32.zip
glib_2.28.8-1_win32.zip
gettext-runtime_0.18.1.1-2_win32.zip
A alternative without glib dependency is pkg-config-lite.
Extract pkg-config.exe from the archive and put it in your path.
Nowdays this package is available using chocolatey, then it could be installed with
choco install pkgconfiglite
I did this by installing Cygwin64 from this link https://www.cygwin.com/
Then - View Full, Search gcc and scroll down to find pkg-config.
Click on icon to select latest version.
This worked for me well.
I would like to extend the answer of #dzintars about the Cygwin version of pkg-config in that focus how should one use it properly with CMake, because I see various comments about CMake in this topic.
I have experienced many troubles with CMake + Cygwin's pkg-config and I want to share my experience how to avoid them.
1. The symlink C:/Cygwin64/bin/pkg-config -> pkgconf.exe does not work in Windows console.
It is not a native Windows .lnk symlink and it won't be callable in Windows console cmd.exe even if you add ".;" to your %PATHEXT% (see https://www.mail-archive.com/cygwin#cygwin.com/msg104088.html).
It won't work from CMake, because CMake calls pkg-config with the method execute_process() (FindPkgConfig.cmake) which opens a new cmd.exe.
Solution: Add -DPKG_CONFIG_EXECUTABLE=C:/Cygwin64/bin/pkgconf.exe to the CMake command line (or set it in CMakeLists.txt).
2. Cygwin's pkg-config recognizes only Cygwin paths in PKG_CONFIG_PATH (no Windows paths).
For example, on my system the .pc files are located in C:\Cygwin64\usr\x86_64-w64-mingw32\sys-root\mingw\lib\pkgconfig. The following three paths are valid, but only path C works in PKG_CONFIG_PATH:
A) c:/Cygwin64/usr/x86_64-w64-mingw32/sys-root/mingw/lib/pkgconfig -
does not work.
B) /c/cygdrive/usr/x86_64-w64-mingw32/sys-root/mingw/lib/pkgconfig -
does not work.
C) /usr/x86_64-w64-mingw32/sys-root/mingw/lib/pkgconfig - works.
Solution: add .pc files location always as a Cygwin path into PKG_CONFIG_PATH.
3) CMake converts forward slashes to backslashes in PKG_CONFIG_PATH on Cygwin.
It happens due to the bug https://gitlab.kitware.com/cmake/cmake/-/issues/21629. It prevents using the workaround described in [2].
Solution: manually update the function _pkg_set_path_internal() in the file C:/Program Files/CMake/share/cmake-3.x/Modules/FindPkgConfig.cmake. Comment/remove the line:
file(TO_NATIVE_PATH "${_pkgconfig_path}" _pkgconfig_path)
4) CMAKE_PREFIX_PATH, CMAKE_FRAMEWORK_PATH, CMAKE_APPBUNDLE_PATH have no effect on pkg-config in Cygwin.
Reason: the bug https://gitlab.kitware.com/cmake/cmake/-/issues/21775.
Solution: Use only PKG_CONFIG_PATH as an environment variable if you run CMake builds on Cygwin. Forget about CMAKE_PREFIX_PATH, CMAKE_FRAMEWORK_PATH, CMAKE_APPBUNDLE_PATH.
Install mingw64 from https://sourceforge.net/projects/mingw-w64/. Avoid program files/(x86) folder for installation. Ex. c:/mingw-w64
Download pkg-config__win64.zip from here
Extract above zip file and copy paste all the files from pkg-config/bin folder to mingw-w64. In my case its 'C:\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin'
Now set path = C:\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin
taddaaa you are done.
If you find any security issue then follow steps as well
Search for windows defender security center in system
Navigate to apps & browser control> Exploit protection settings> Program setting> Click on '+add program customize'
Select add program by name
Enter program name: pkgconf.exe
OK
Now check all the settings and set it all the settings to off and apply.
Thats DONE!
Another place where you can get more updated binaries can be found at Fedora Build System site. Direct link to mingw-pkg-config package is: http://koji.fedoraproject.org/koji/buildinfo?buildID=354619
for w64-based computers you have to install mingw64. If pkg-config.exe is missing then, you can refer to http://ftp.acc.umu.se/pub/gnome/binaries/win64/dependencies/
Unzip and copy/merge pkg-config.exe into your C:\mingw-w64 installation, eg. into on my pc into C:\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin
In 2022 VS Code works with CMake & pkgconfig out of the box (add pkgconf && vcpkg-pkgconfig-get-modules to your vcpkg.json)
From: https://github.com/JoinMarket-Org/joinmarket/wiki/Installing-JoinMarket-on-Windows
This guide describes how to install JoinMarket and its dependencies (python, libsodium, secp256k1) on Windows.
Some or all of this may or may not work for all versions of Windows. Reports appreciated. It is not claimed to be in any way comprehensive. Verification of downloads are your own responsibility.
Install JoinMarket - go to https://github.com/JoinMarket-Org/joinmarket/releases and download the most recent release. Unzip it into any location you choose.
You will need to install MinGW from here or go to their website. After a few introductory screens, you will be shown a windows with some optional components that you have to choose; this basic setup is sufficient:
From "Basic Setup" in the left menu:
mingw-developer-toolkit
mingw32-base
mingw32-gcc-g++
msys-base
Once you have chosen these, choose "Update" from the main menu first item. These components will be installed into C:\MinGW\bin. Once that is complete, you should have this dll: libgcc_s_dw2-1.dll in that folder C:\MinGW\bin, along with a lot of other files; I'm mentioning this file explicitly, since it's needed specifically for libsecp256k1 to operate in this setup.
Next, you must make sure C:\MinGW\bin is added to your PATH variable. Here's one guide to how to do that; you must append ;C:\MinGW\bin to the end of the path before continuing.
Install Python from https://www.python.org/ftp/python/2.7.11/python-2.7.11.msi. Run the executable. Choose to install the feature Add python.exe to Path (it's the last option in the installer, off by default - switch it on) on local hard drive during installation; Python should then be installed in C:\Python27 (EXTRA NOTE: the most recent 2.7 installation linked here seems to install pip automatically, which is very useful for step 4)
Check that Python runs. Open a new command prompt as administrator by typing cmd.exe into the Start menu and pressing Ctrl+Shift+Enter. Type python and you should see something like:
Python 2.7.11 (default....
....
>>>
Exit the Python console with exit() or by pressing Ctrl+C. Now, make sure your version of pip is up to date: run the command: python -m pip install --upgrade pip.
Go to the directory C:\Python27\Lib\distutils and add a new file, called distutils.cfg. Inside it, put:
[build]
compiler=mingw32
Close and save the file.
Next, you need to install the dll for libnacl. First go to https://download.libsodium.org/libsodium/releases/ and choose the file libsodium-1.0.4-msvc.zip to download. Unzip anywhere, and then copy the file libsodium.dll from the directory \Win32\Release\v120\dynamic (do not use v140), and paste it into root joinmarket directory (the same directory where README.md lives). Then you need to address the Visual C++ 2013 runtime dependency. Do so by going to www.microsoft.com/en-us/download/details.aspx?id=40784 and clicking Download. Choose x86 even on a 64-bit system, and run the executable.
Note that after doing this, you must run pip install -r requirements-windows.txt from the Joinmarket root directory (where the README.md file is) and should not get an error message (this will install/check the python packages libnacl and secp256k1(-transient)).

Resources