Strange behavior of Eclipse Neon - eclipse-cdt

I use Eclipse with CDT plugin for my C/C++ development. And I use MinGW compiler. Environment Path set properly. All the setting done properly in Eclipse. While editing the source code its working fine but after compilation when I try to execute the source code sometimes it says it cannot open the .exe file or sometimes doesn't show anything when there is some input to take. When I stop the execution pressing the red button program gets executed completely with default values.
But everything is fine if I compile and run the same source code using notepad and the command prompt. Please help.

A common problem is that if the program is currently executing, the program file is opened by the system and cannot be reopened for writing by the compiler (or more exactly by the linker). This problem can be easily reproduced by starting the program in debug mode and stop it at a breakpoint. Then, while the process is active, change a line in source and ask for a new build: you will get the error saying that the exe file cannot be opened.
How to fix: ensure to close any possible execution of the program when the error happens and rebuild

Related

Show C++ source files in Android Studio when debugging with lldb

I have an Android application with native c++ librairies.
I can debug c++ code with lldb, I can break, I can see the stack, the variables and their values.
The command 'source info' displays the correct break line code.
I use the command 'settings set target.source-map' to map the source code files, the command seems to work fine, no error, but Android studio don't open the corresponding source files in the editor... nothing happens when I double click in the debugger stack.
Sometime ago, it works correctly, I don't know if something changed in my compilation process or in Android studio, but it doesn't work anymore.
Any ideas ?

Eclipse C/C++ "Permission Denied" error

I'm using Eclipse Helios in Windows7 for C/C++ programming. I wrote a basic C++ code and tried to compile. The output is:
**** Incremental Build of configuration Release for project Programming Project **** Info: Internal Builder is used for build g++
-o "Programming Project.exe" "src\ch_3_excercises.o" c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/ld.exe:
cannot open output file Programming Project.exe: Permission denied
collect2: ld returned 1 exit status
How can I fix this error?
All you have to do is go to project on the menu bar and then click clean project. Clean all of your projects and then it should work.
The same problem with me while editing my code.the easy way i used is ::::::::
press the red button(Terminate) before editing your code then run your code
it is tested and works
I know this is an old question, but it probably does that because you are interrupting the flow of your program, for instance using scanf(), and not actually giving the input it requires, so when you use the command Build the project, then eclipse is waiting a stream from your keyboard (for instance, maybe it's a different type of program, but follow me here).
Once you know than that is the problem, then you might wanna keep an eye in what is that you are not giving to the project and that it is expecting you to; and the way to stop this annoying error the next time you get it, is that in your console view you press the red button.
That will happen if the program is still running in another window. The .exe file stays open until the program finishes execution, and you can't delete a file while any processes have it open.
I don't use Eclipse for C/C++ development, and the problem almost can't happen with Code::Blocks, but this happens very often with Visual C++. Just close the other window and rebuild.
Check your quarantine folder of your antivirus. If you see the executable file, then add it to the Trust list or White list. Your problem should be solved.
It means the same .exe file is running in your system.
A program cannot be build when its already running.
So the simple and most obvious thing to do is:-
Open task manager
Find <yourfilename.exe> under processes
Right click and end task
This stops it from running in background.
So you can build your program anew and run.

My C++ program gets" ... .exe has stopped working" windows 7 error

I have written a C++ program in Visual Studio 2010. It builds and runs fine in the IDE (even when running without debugger, in Release mode). However, whenever I run the executable from the command prompt, I get an "... .exe has stopped working" error message.
How can I figure out what's causing it to crash? Do I have to include something else in the command line if I use additional libraries/headers? Are there errors that make it through the Visual Studio IDE, but cause problems when running the program on the outside?
I'm not including my code, because there's way to much of it...
Help is greatly appreciated.
If your program had been rendered in Debug mode, try rendering it in Release mode and then retry.
The problem was incomplete directories for the files I was loading. I neglected to check for a successful open or use try/catch. It was running fine in the IDE because the file directory was in a subdirectory of the working directory. When I tried to run it from the command prompt, the relative directory was no longer valid. I changed the filenames to their complete directories, and everything worked fine.

Eclipse CDT Console output not showing up in debug with path and not showing up in run without path

I'm trying to get Eclipse CDT (64 bit eclipse) working on Windows 7 with GCC. When I first got GDB working (that was a challenge in itself), running the program in debug mode was the only way I got output. Running it normally didn't give any console output. After hours of googling, I figured out that if I added C:/cygwin/bin to my environment path in eclipse, I could get output when running the program normally. Then I ran it in debug mode and there was no output. I tested this a couple of times to make sure it was the addition of the path causing the problem. This is the program I was running,
#include <iostream>
using namespace std;
int main() {
cout << "Hello World!" << endl;
return 0;
}
So how can I get both normal and debug modes working, and why did I have to include that path in the first place (it's already in my cygwin path and why does CDT need it?) ? Also, why is it that if I add a path to my Run configurations it will also be added to my Debug configurations?
From wiki eclipse:
In Eclipse CDT on Windows, standard output of the program being run or debugged is fully buffered, because it is not connected to a Windows console, but to a pipe. See bug 173732 for more details. Either add flush calls after every printf or add the following lines at the start of the main function:
setvbuf(stdout, NULL, _IONBF, 0);
setvbuf(stderr, NULL, _IONBF, 0);
I don't think I can answer everything but I use exactly the same set-up as you and I've had to deal with quite a few issues like this (I'm wondering if you had trouble how to juggle using the 32-bit/64-bit JVM and Internet browsing)!
The cygwin/bin path must be specified because that is where gcc, gdb and all the other cygwin tools and dlls are located (I'll assume you're using cygwin flavour of gcc rather than MinGW flavour). I believe you must specify it in the Windows environment (using a win32 file path) because Eclipse is running using the Windows JVM and therefore deals with win32 paths. Consequently, it doesn't matter that cygwin/bin is added to the PATH variable in the cygwin environment. CDT is looking for cygwin using Eclipse, and Eclipse needs to find cygwin1.dll from Windows.
I might be totally wrong, but if I had to guess I would say that you need to make absolutely sure you have properly set the PATH environment variable correctly for both configurations.
One thing to note is that in Eclipse there is no difference between a configuration shown in the Debug Configurations window and one with the same name in the Run Configurations window. The only difference between the two windows is that one will run the program without using a debugger and has tabs for setting debug settings. Therefore it's no surprise that changing settings in one will also affect the other.
As you may know, for many projects the build system is set up to produce two (sometimes more) sets of binaries: one with debugging info/symbols (DEBUG) and one without (RELEASE). In this case, you normally have two configurations in Eclipse: one to run the DEBUG binary and one to run the RELEASE binary. Both of these will show up in both the Debug Configurations window and in the Run Configurations window. The point is that you can run DEBUG either with or without gdb, but RELEASE cannot be used by gdb.
That said, I'm not sure why adding the correct path to the run configuration would stop the DEBUG binary from outputting to the console. I suspect something else is going on here, perhaps a mismatch of debug info and debugger.
To (hopefully) answer your question as to how to get both configurations working, go the whole-hog and just add C:\cygwin\bin; to the Windows PATH environment variable. I'm guessing that will allow both to work. I'll assume you know how to do that but please post a comment if not.
The other thing to try would be to compile and run the program from a cygwin shell. If it works there it's probably a safe bet that your PATH environment variable is not set correctly when using eclipse.
Hope that helps!
Adding the Path was correct before gdb 7.3. Now when I add the path I can no longer use breakpoints as it cannot find the dll files as they are no longer part of the path. To fix this you can easily add the entire path from the environment by following these instructions.
left click the project
enter the RUN/DEBUG settings for the project
select the executable
click edit
select Environment Tab
click Select...
scroll down to Path (Case sensitive)
check mark Path
press OK
press OK
press OK
You can see the dll problem as it appears in the gdb console
error,msg="During startup program exited with code 0xc00000be."
or
error,msg="During startup program exited with code 0x00000135."
and you may get an error window pop up saying it could not clear the breakpoint
You need to set up linker
I am using MinGW.
Follow below steps.
Goto Project > Properties > C/C++ Build > Settings > Tool Settings (Tab) > MinGW C++ Linker (Option) > Add Command (g++ -static-libgcc -static-libstdc++) (default command is only g++)
Don't debug or run C or C++ applications from inside Eclipse if they target Cygwin. TK link to "you're gonna have a bad time" meme.
There are problems with Cygwin stdout/stderr that don't show up if you run the programs from the normal Cygwin console (where you would be running bash), but they do show up in pretty much every other way you can run them.
The normal way that programs run other programs in Linux and other posix-supporting environments is to reroute the i/o to a pty. Cygwin can't support pty's 100% in Windows.
Some of the problems can be ameliorated by the setvbuf calls in #infoartenovo's answer.
A flip side of this problem is that applications written to use Windows' Console API don't work well in ptys.
We are all collateral damage in an unwinnable war.
http://cygwin.com/ml/cygwin/2011-12/msg00236.html
https://code.google.com/p/mintty/issues/detail?id=56

Can't run programs on my mac

I've been programming on windows for about three months now and when my computer finally died I bought a mac. I'm really happy with it except I can't figure out how to run my c++ programs.
On windows it would open up in command prompt so I figured it would do the same thing except with terminal.
After I write my programs (in Xcode) I can compile them and it'll tell me if there are syntax errors but the run and run related buttons are all Grey and unusable.
It's incredibly annoying that I can't see how the program that I put 4 hours into runs and even more annoying that I don't know if I've made a runtime error. Someone please help.
Thank you very much, James
Assuming that you're trying to write a program that you interact with on the command line, you want to create a "Command Line Tool" project, found under "Application" in the Mac OS X section of the New Project dialog. Choose "C++ stdc++" from the "Type" dropdown, as well. This will give you a main.cpp that should look familiar to you, with a "Hello, World!" sample.
Note that when you Run this program, it might appear to do nothing - You need to open the Console (from the Run menu, or shift+command+R) to see your output.
Xcode deals in projects. If you're just opening the source file, there is no project. Create a project with the files in it and Xcode should let you run it.
Alternately, you can just use G++ on the command line to compile your files and run the resulting executable there.
Try compiling from the terminal as stated above. The a.out file should be created, and should run as long as Xcode has been installed. It should work fine from the terminal, and point out any errors in the compiler's output.
To runs the a.out file, ensure you are in the files directory in terminal and type ./a.out