Compiling with MingW in CMD shows libisl-21.dll was not found - c++

I was trying to compile a .cpp file using command-line, but I am encountering an error.
I have installed MinGW properly from the official installer.
Also, I sat the path to the bin folder of MinGW which is in C drive.
Now when I try to compile file with command:
g++ demo.cpp -o demo.exe
I get a "CC1plus.exe - System error" message-box, like:
The code execution cannot proceed because libisl-21.dll was not found.
Reinstalling the program may fix this problem.
I can't find the .dll file anywhere. What seems to be going wrong? Any lead? I have reinstalled MinGW multiple times.
Thanks,

libisl-*.dll is part of the MinGW-w64 distribution.
I'm not sure older MinGW also provides it, but you should use MinGW-w64 anyway (e.g. from https://winlibs.com/ or installed via MSYS2's pacman) as it's much better maintained and supports newer Windows versions (including 64-bit).
Your problem is that g++.exe depends on libisl-21.dll but can't find it.
Check the following:
From which location is g++.exe being called? This should be the first location containing g++.exe in the PATH environment variable in the environment where you were running g++.exe from (e.g. if this is the Command Prompt type ECHO %PATH% to see its value).
Does the folder containing g++.exe also contain libisl-21.dll?
Is your MinGW setup broken or can it be uninstalled+reinstalled?
Do you have multiple MinGW / MinGW-w64 installations on your system that are getting mixed up (e.g. because multiple are point to via the PATH environment variable)?
You can try to unpack a standalone MinGW-w64 from https://winlibs.com/ - which doesn't have an installer and will not interfere with your other installed MinGW(-w64) releases - and try to use g++.exe from its bin folder by specifying it's entire path.

I'm working on an embedded program, but want to test out code snippets on g++ on Windows because it's much faster than building & loading on the embedded system itself. Our embedded system's unittests run on C:\MinGW\bin\gcc\g++.exe, so that's the copy of g++ I was trying to use when I had this problem. Using hints from Brecht Sanders's answer, this solved my problem:
In a "build.bat" file I created local to my code snippet "ftest.cpp" file:
#setlocal
#set ORIGINAL_PATH_VARIABLE=%PATH%
#set PATH=C:\MinGW\bin;C:\MinGW\bin\gcc;%ORIGINAL_PATH_VARIABLE%
g++ -std=gnu++11 -g -Wall -Werror ftest.cpp
(I searched for and found libisl-21.dll at C:\MinGW\bin.)
Hopefully someone finds this helpful.

Related

How can i use neovim and coc.nvim for develop windows c++ apps on linux

I develop c++ apps on linux and i use neovim with coc.nvim and coc-clangd plugins.
I want to develop an app for windows but i comfort with linux and neovim so i want to use them for it. But i get some include errors with some windows headers (etc. "windows.h").
I use linux only for writing the code and i'll compile the program on windows. How can i prevent this errors and use windows headers with coc.nvim?
i'll compile the program on windows
You can cross-compile it from Linux. It's only marginally more difficult than getting the code completion to work.
Get the standard library headers (and libraries, if you want to cross-compile) from MinGW.
Your package manager might have those, or you can get them from https://winlibs.com/.
I prefer getting those from MSYS2, and made scripts to automate this (since MSYS2 is otherwise Windows-only):
git clone https://github.com/holyblackcat/quasi-msys2
cd quasi-msys2/
make install _gcc
Figure out the Clang flags needed to cross-compile.
Unlike GCC, which for every target platform requires a separate compiler distribution, Clang is inherently a cross-compiler. You only need a single Clang distribution to compile for any supported platform.
Download Clang from your package manager, and point it to the freshly downloaded headers and libraries.
Following flags work for me: clang++-14 1.cpp --target=x86_64-w64-mingw32 --sysroot=/path/to/quasi-msys2/root/mingw64 -fuse-ld=lld-14 -pthread -stdlib=libstdc++ -femulated-tls -rtlib=libgcc.
--target and --sysroot are crucial. The latter needs to point to the files you've downloaded. The remaining flags are less important.
Running this should produce a.exe, runnable with wine a.exe.
Feed the same flags to Clangd.
There are several ways to set compiler flags for Clangd.
The easiest one is to create a file named compile_flags.txt in your project directory, and put the flags into it, one per line:
--target=x86_64-w64-mingw32
--sysroot=/path/to/quasi-msys2/root/mingw64
-fuse-ld=lld-14
-pthread
-stdlib=libstdc++
-femulated-tls
-rtlib=libgcc
Then Clangd should do the right thing for any source files in this directory.
Apparently, my Quasi-MSYS2 can somewhat automate this.
After running the commands above (make install _gcc and others), run make env/shell.sh, and run your editor from this shell.
Replace compiler_flags.txt with compiler_commands.json with following contents:
[
{
"directory": "/your/sources",
"file": "/your/sources/1.cpp",
"command": "win-clang++ 1.cpp"
}
]
Where win-clang++ is a Clang wrapper I ship, which automatically adds the flags I listed above.
Configure your editor to add following flag to Clangd: --query-driver=/path/to/win-clang++ (use which win-clang++ from quasi-msys2 shell to get the full path).
This makes Clangd obtain the right flags automatically from this wrapper.
You can't use windows.h while you're compiling a Linux native application. If want to make your application platform ready and you're using some kind of OS native cals, then you have to probably use defines like #if _WIN32/__linux__ and so on. At the end, you can cross-compile your application to Windows while you're running on Linux as well.

MinGW path set but not being found at Powershell

I just started learning C++ in class, and I have trouble setting up the built environment.
Our class uses MinGW and VS code for default building environment, so I followed the class guideline to install necessary MinGW libraries and added the directory of MinGW bin folder to environment variables(path).
So it worked well for the first time, but after reboot VS code cannot find gcc and g++. Typing gcc --version and g++ --version at cmd works well; it shows version info. However, typing that in Powershell(which VS code uses) does not work anymore.
I'm totally new to C++ and related environment, so I definitely have to fix this trouble. Thanks for your help in advance.
Try to add a system environment variable, and the var name is "g++" with the value "C:\MinGW\bin\g++.exe"(replace this path with your g++.exe file path).Maybe you should restart your computer to apply this operation if the windows OS version is windows 10.

Where is G++in MinGW install?

I installed MinGW and set the variable PATH. Then g++ in the terminal worked only ONCE, then the terminal does not recognize g++ only gcc, as you can see:
I tried to reinstall it, but it did not work. Still the g++.exe file is missing.
And when I try to install it, the terminal says I already installed it, like this:
Just type echo $PATH then you should have your g++ executable file on that path.
I already have the solution, my antivirus deleted g++.exe very time when i installed it.

MinGW ís not working

I installed the C++ compiler MinGW following this tutorial, but when i used the consol commands:
> gcc --version
g++ (GCC) 4.8.1
......
> g++ --version
g++ (GCC) 4.8.1
......
> gdb --version
GNU gdb (GDB) 7.6.1
i dont receive any information and the console prints 'gcc is not recognizable as internal or external command'
When you execute step 3:
Setup environment variable PATH to include "<MINGW_HOME>/bin" where <MINGW_HOME> is the MinGW installed directory that you have chosen in the previous step.
Be aware that changes made to your path in the control panel don't affect existing consoles.
You need to open up a new console for the path to affect it.
The other possibility is that you've modified the path in a console you were working in but this is the wrong way to do it, since that path will not affect future consoles.
You most likely missed this step:
Setup environment variable PATH to include "<MINGW_HOME>/bin" where <MINGW_HOME> is the MinGW installed directory that you have chosen in the previous step.
What is the output of this command?
echo $PATH
If it does not include "<MINGW_HOME>/bin", you need to make the necessary adjustment.
Besides, that tutorial is somewhat dated. Cygwin Ports does include packages for MinGW, plus precompiled libraries, available from Cygwin's setup.exe. The packages are:
mingw64-i686-gcc
mingw64-i686-gcc-g++
or
mingw64-x86-gcc
mingw64-x86-gcc-g++
depending on your architecture. If you use those packages, the compiler will be installed in /usr/bin (which already is in your PATH), and you can access it (e.g. as i686-w64-mingw32-gcc) right away.

Netbeans and MinGW-w64

I'm trying to configure my NetBeans on win7 64bit, to work with the MinGW-w64.
So I put in the %PATH% variable the following paths of the compiler:
C:\mingw-w64-bin_i686\mingw\bin
C:\minGw-MSYS\msys\bin
C:\mingw-w64-bin_i686\libexec\gcc\x86_64-w64-mingw32\4.7.0
Then I opened NetBeans and this was configured:
The configuration in NetBeans
I tried to compile a little test program but I received this error:
g++.exe: fatal error: -fuse-linker-plugin, but liblto_plugin-0.dll not
found compilation terminated. make[2]: *
[dist/Debug/MinGW-Windows/test.exe] Error 1 make1: [.build-conf]
Error 2 make: ** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 1s)
I do have this file in C:\mingw-w64-bin_i686\libexec\gcc\x86_64-w64-mingw32\4.7.0
what am I missing?
Right, after months of putting this off I've finally sat down and done it. I'll probably make a more detailed post on my blog with pretty pictures but here is a trimmed down SO version which will hopefully be enough for you (and everyone else) to get going with.
Prerequisites
Remove MinGW, MSYS and CMake if you have them and can afford to lose them (we will reinstall MinGW (obv.) and MSYS but not CMake as it doesn't appear to be needed.)
Netbeans or other suitable IDE
64bit Windows.
EnvMan (optional but handy for managing Windows Environment
variables.)
Installation
MinGW-W64 C compiler and MSYS
Download and install MinGW-W64
http://mingw-w64.sourceforge.net/ (link is on the left menu with a
hyperlink called 'WIN64 Downloads'.)
There are a lot of versions which can be a bit complicated. We are
going with mingw-w64-bin_i686-mingw_20111220 (although the numbers at
the end may be different) which basically says we want the version
with the windows binaries.
Once the download is complete (about 300mb so 10min or so) extract to
C:\MinGW-W64 or similar. Make sure there aren't any spaces in the
path!
Download MSYS for MinGW-W64
Took a bit of searching
http://sourceforge.net/apps/trac/mingw-w64/wiki/MSYS is the wiki for
it and
http://sourceforge.net/projects/mingw-w64/files/External%20binary%20packages%20%28Win64%20hosted%29/MSYS%20%2832-bit%29/
is where I found the download and the version I went with was
MSYS-20111123
Once the download is complete extract the files to C:\MSys or
similar. Make sure there aren't any spaces in the path!
Setup
Add 'C:\MinGW-W64\bin' to your Windows PATH variable.
Add 'C:\MSys\msys\bin' to your Windows PATH variable.
Start Netbeans and go to Tools -> Options -> C/C++.
Click 'Add' under 'Tool Collection' and select the base directory of
MinGW-W64 (C:\MinGW-W64\bin).
Select 'MinGW' from 'Tool Collection Family' if it isn't
auto-detected and click 'OK'.
Set the 'C Compiler to C:\MinGW-W64\bin\x86_64-w64-mingw32-gcc.exe.
Set the 'C++ Compiler to C:\MinGW-W64\bin\x86_64-w64-mingw32-g++.exe.
Set the 'Make Command' to C:\MSys\msys\bin\make.exe.
And that should be it!
I should note that I am using the system to compile a library file to be use via JNI so have some additional steps for that which I missed out as they weren't needed here. However I made a quick 'Hello World' program and it compiled and ran nicely.
Happy coding!
I have just downloaded the latest automated build, unzipped it, added the main bin directory to path, and run:
x86_64-w64-mingw32-gcc test.cpp -o test.exe
and
x86_64-w64-mingw32-gcc -fuse-linker-plugin test.cpp -o test.exe
and it works. The same for the i686 variant. Your IDE is doing something wrong. Or you shouldn't have messed with the files. Or you shouldn't have removed the prefixes. Seriously.
PS: You only have to add the main "bin" directory to PATH, all the rest is wrong.
With some searching via your favorite Internet search engine, I have come across a better approach to quickly add MinGW-x64 to a Windows 64-bit system. On the Sourceforge site is MSYS2.
While following the installation directions and obtaining the most up to date packages, there may be a time out at the primary mirror site on Sourceforge. If so, follow the mirror site update directions and update the three pacman text files in the respective MSYS2 directory (e.g. /etc/pacman.d). Then proceed to complete the package updates from the MSYS2 installation directions.
Within the MSYS2 packages are things like gcc, llvm, make, dmake, etc. Here is the command used from the MSYS2 command line shell (e.g. bash) to install the GNU make utility:
$ pacman -S msys/make
The executable location it will be placed is: /usr/bin inside the MSYS2 command shell. As far as configuring Netbeans for where make.exe is located, the Windows path is:
MSYS2 installation directory\usr\bin\make.exe
(e.g. C:\msys64\usr\bin\make.exe).
To successfully build C++ with Netbeans, I used the GNU make package (e.g. msys/make). Then in order to use the default make files that Netbeans manages, and to not interfere with other C++ compilers within your Windows installation (e.g. Visual Studio, Intel, CLang from Visual Studio, etc.), run Netbeans from the MinGW-x64 command shell provided by MSYS2. In this way, the environment variables and other things like:
ls rm mkdir
will indicate successful execution and compilation within the Netbeans internal terminal window. I opened the MinGW-w64 Win64 Shell by navigating to the installed shortcut from MSYS2's installation. Then pasted into the MinGW-x64 shell command line, the Target property value from the Netbeans Windows desktop shortcut:
$ "C:\Program Files (x86)\NetBeans 7.4\bin\netbeans.exe"
And then could finally create the respective debug and release object and executable files. I also modified the Netbeans project output to be within the MSYS2 directory structure. Then run the executable within the MSYS2 MinGW-x64 shell. Running from the Netbeans IDE produces this error message:
Unable to start pty process: The application failed with exit code
-1073741515 (0xc0000135).
If the MSYS2 path were in the computer system's PATH environment variable, then perhaps this error would not happen.