Eclipse CDT error: Unable to compile - c++

I tried to run a simple Hello world program. I am getting this error when I try to build it. What does it mean and how do I resolve it? I am using Windows 7 and I have MinGW and MSys in the %PATH%.
**** Build of configuration Debug for project learn ****
**** Internal Builder is used for build ****
g++ -IC:\MinGW\lib\gcc\mingw32\4.5.2\include\c++ -IC:\MinGW\libexec\gcc\mingw32\4.5.2 -O0 -g3 -Wall -c -fmessage-length=0 -osrc\learn.o ..\src\learn.cpp
g++: CreateProcess: No such file or directory
Build error occurred, build is stopped
Time consumed: 78 ms.
Code:
#include <iostream>
int main()
{
std::cout << "Hello, world!" << std::endl;
return 0;
}
My %PATH% is:
C:\Users\Hari>echo %PATH%
C:\Program Files (x86)\MiKTeX 2.8\miktex\bin;C:\sml\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\WIDCOMM\Bluetooth Software\;C:\Program Files\WIDCOMM\Bluetooth Software\syswow64;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files (x86)\Common Files\Roxio Shared\10.0\DLLShared\;C:\Program Files (x86)\Common Files\Roxio Shared\DLLShared\;C:\strawberry\c\bin;C:\strawberry\perl\site\bin;C:\strawberry\perl\bin;C:\Program Files (x86)\QuickTime\QTSystem\;G:\svn\bin;C:\Program Files\TortoiseSVN\bin;C:\Program Files\SlikSvn\bin\;C:\cygwin\bin\;C:\Program Files\apache-maven-2.2.1\bin\;C:\PsTools;C:\MinGW\msys\1.0\bin;C:\MinGW\bin
I am able to run g++ from cmd:
C:\Users\Hari>g++ --version
g++ (GCC) 4.4.3
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

I found the same problem with a C HelloWorld invoking the MinGW gcc compiler. After quite a bit of experimentation, I have found that the MinGW binutils package is to blame! The latest one doesn't play nice with CDT for some reason. Use this one instead and it will work :)
binutils-2.21-2-mingw32-bin.tar.lzma
NOTE: versions 2.21-3 and later seem to have the problem.
Additionally, the latest GDB 7.3 seems to hang too. Use this one:
gdb-7.2-1-mingw32-bin.tar.lzma
Happy coding :)
PS: I don't even have MinGW or MSYS in the path. As long as MinGW is in C:\MinGW things seem to magically work.

Try rebooting your system after setting your environment. Please refer to here:
CreateProcess: No such file or directory

How did you create the project? Start with the New->C++ Project. Then under Executable pick the "Hello World C++ Project". On the Toolchains I pick the MinGW GCC toolchain but it's possible you don't have that installed. At any rate this creats a fully compilable executable that makes a good starting point for learning. It puts all the include directories, library paths etc in the project settings.

I had similiar problem.
Just deleted "C:\MinGW\bin" from the PATH, reinstalled MinGW and it worked. Ecllipse or CLion don't need PATH to be set. CLion even warns that "C:\MinGW\bin" should not be in the PATH.

I used an artifice.
I have installed the Dev-Cpp and within it comes installed Mingw32.
I copied the Mingw32 to directory c: and rename the mingw32 to c:\MinGW
and include to %PATH%. It worked very well.

Related

Compile C++ Windows exe standalone files with MSYS2

I've recently started using Msys2 to install gcc compiler to make some exe for Windows. It works very well, but there's a problem when passing my exe to my brother. His laptop has not msys2 installed and when he tries to run my exe some errors occur. Seems like few dll files are necessary to use my exe (like msys-2.0.dll).
I've found out that those files are used by msys2 to "fake" the OS on the machine pretending it's a POSIX one. Is there a way to compile standalone exe for windows with msys2? I would like my brother to be able to use my exe without installing msys or else.
Here are all the details to understand better my situation:
g++ HelloWord.cpp -o Helloword is the line I use to compile
C:\msys64\mingw64\bin here's the path where g++ is stored
All the exact error messages I receive from windows after double clicking on the exe file that has been generated. Note that these messages do not appear on the CMD, but in a classic Windows error pop-up:
The program can't start because msys-2.0.dll is missing from your computer.
Try reinstalling the program to fix this problem.
The program can't start because libstdc++-6.dll is missing from your computer.
Try reinstalling the program to fix this problem.
The program can't start because libgcc_s_seh-1.dll is missing from your computer.
Try reinstalling the program to fix this problem.
Fixed:
I've resolved the issue just using the g++ parameter -static. Is it an overkill?
My version of MinGW is a bit old ...
C:\example>where g++
C:\misc\mingw810_64\bin\g++.exe
C:\example>g++ --version
g++ (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 8.1.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
But same idea:
C:\example>cat > compile_me.cpp
#include <iostream>
int main () { std::cout << "hi" << std::endl; }
^Z
C:\example>g++ compile_me.cpp -o compiled.exe
C:\example>compiled.exe
hi
C:\example>dumpbin /dependents compiled.exe
...
Image has the following dependencies:
KERNEL32.dll
msvcrt.dll
libstdc++-6.dll
...
In that case (dynamically linked stdlib) you'd deploy libstdc++6.dll with the executable, installing it to the same path as the exe (the other two are generally present in the windows system path).
If you want to drop that dependency, use -static:
C:\example>g++ compile_me.cpp -o compiled.exe -static
C:\example>compiled.exe
hi
C:\example>dumpbin /dependents compiled.exe
...
Image has the following dependencies:
KERNEL32.dll
msvcrt.dll
...
Deploying that .exe alone should be fine.
The file size will be larger but that's not a huge deal these days. Also your MinGW / MSYS install might come with strip:
C:\example>dir compiled.exe
Volume in drive C is Windows
Volume Serial Number is D2BA-C6F0
Directory of C:\example
09/24/2022 06:49 PM 2,389,120 compiled.exe
1 File(s) 2,389,120 bytes
0 Dir(s) 135,945,314,304 bytes free
C:\example>strip compiled.exe
C:\example>dir compiled.exe
Volume in drive C is Windows
Volume Serial Number is D2BA-C6F0
Directory of C:\example
09/24/2022 07:03 PM 838,656 compiled.exe
1 File(s) 838,656 bytes
0 Dir(s) 135,944,765,440 bytes free
C:\example>compiled.exe
hi
If there are other dynamic libraries that your particular executable ends up depending on, and the vendor has chosen not to provide statically linked alternatives, then you'll have to just deploy them with the exe. It's generally easy enough to just throw everything in a zip file or use your favorite scriptable installer.
(Note: dumpbin ships with Visual Studio; and can be found in some appropriate subdirectory in VC\Tools in the vs install path).
MSYS2 compiles native PE32 executables. It does not rely on any magic msys environment or static linking.
Get yourself a dependency walker and look to see what DLLs your app needs to run. Anything not in a Windows subdirectory should be where you focus your attention. Also make sure your app does not require any special Microsoft redistributable dependencies.
Ultimately, you should be creating an installer for your application to handle dependencies. I personally like Inno setup, but plenty of others exist that are well liked also.
The OP has solved their problem but for anyone else who finds this:
Make sure you launch MSYS2 by clicking on mingw64.exe or the equivalent shortcut.
Run which g++ to make sure you are using /mingw64/bin/g++. If it shows some other g++ then run pacman -S mingw-w64-x86_64-toolchain to install the toolchain.
Compile your code with g++ and use the -static option.
Run ntldd yourprogram.exe to check which DLLs your program is using and make sure they are part of Windows, not part of MSYS2.

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

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.

Invalid toolchain error with Code::Blocks

"Hello - Debug" uses an invalid compiler. Probably the toolchain path within the compiler options is not setup correctly?! Skipping...
I get the above message when I try to run a simple HelloWorld program as below.
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!" << endl;
return 0;
}
Any idea as to why this is happening and how I could solve it would be useful
FYI : Im using the GNU GCC compiler at the moment, I tried changing this too but there was no use.
Thanks to #Thrustmaster's comment. For anyone stuck with a similar problem in the future just go to Settings->Compiler and Debugger->ToolChain Executables ->Click Auto Detect on the compiler's installation directory . Presto! The IDE auto-detects the path and works!
Well, you could use a terminal (this assumes Linux or Mac OSX, and that GCC is installed):
g++ -o hello hello.cpp
Or, to install GCC on OSX, you have to install Xcode (the registration is free) and then go into Xcode → Preferences → Downloads → Components, and click on the install button next to "Command Line Tools".
To install GCC on Debian based Linux distros, use this: sudo apt-get install g++.
Go to Settings->Compiler and Debugger->ToolChain Executables
In Compilers installation directory, browse and select your MinGW installed Directory
Also for C compiler, browse and go to bin folder which is inside MinGW and select mingw32-gcc.exe
For C++ compiler, select mingw32-g++.exe from there
For Linker for dynamic libs , select mingw32-g++.exe from there
For Linker for static libs, select ar.exe from there
For Debugger, select gdb.exe from there
For Resource Compiler, select windres.exe from there
For Make program mingw32-make.exe from there
thats how it worked for me
This happens because your compiler settings are not configured. This is how i solved my issue
Download MinGW Instaltion Manager
Download mingw32-gcc and mingw32-g++ compilers through MingGW and apply changes.
go to Codeblocks and then settings/toolchain executables
inside program files section configure the C compiler with mingw32-gcc and C++ compiler with mingw32-g++ compiler

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.

Get "Access is denied" when trying to compile with g++ from command line. Cygwin

I have installed all packages in cygwin. I have also added C:\cygwin\bin to my PATH variable. But when I try to compile a c++ file in command line I get the error 'Access is denied'. The same commands work in the cygwin batch window. Does anyone know what's wrong?
Edit: I changed the permissions for gcc and g++. I no longer get the 'Access Denied' error, but get a new one: "This version of C:\cygwin\bin\g++.exe is not compatible with the version of Windows you're running. Check your computer's system information to see whether you need a x86 (32-bit) or x64 (64-bit) version of the program, and then contact the software publisher.".
Because c:\cygwin\bin\gcc.exe isn't an executable file, it's a cygwin symbolic link.
$ file /bin/gcc
/bin/gcc: symbolic link to `/etc/alternatives/gcc'
$ file /etc/alternatives/gcc
/etc/alternatives/gcc: symbolic link to `/usr/bin/gcc-4.exe'
The underlying file runs just fine.
C:\cygwin\home\Ben>gcc-4 --version
gcc-4 (GCC) 4.5.0
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
I just deleted gcc and g++ and renamed the g++/cc-4.
Unless you're a masochist, always use a Cygwin batch window with Cygwin executables. Also if you're using the Cygwin compiled gcc, you'll need the Cygwin DLL to run the results. The Cygwin website explains why. If you need executables without the Cygwin dll, I'd explore MinGW.
I got the same issue and was because I had pending the reboot after Cygwin installation. After the reboot works for me.