This question already has an answer here:
Trying to setup a C programming environment [closed]
(1 answer)
Closed 7 years ago.
Recently I decided to start coding again in C and C++, so I downloaded Dev-C++ and wrote the standard C Code for "Hello, World!" shown below:
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
printf("Hello World");
return 0;
}
Upon completion, the code compiled with 0 errors or warnings; however, I have a strange problem with running the executable. I'm writing and compiling on Windows 7 machine, and when I open the executable, the command prompt doesn't open to show the resulting program's text, which is what I was told would happen. Opening the Task Manager shows that there are three instances of the executable running at once, and they cannot be terminated with the "End Process" button. I've attempted to compile the same code in two different compilers (i.e. GCC, and Visual Studio) in C and C++ with the same results occurring in both additional environments. It may be worth mentioning that it's a home-build PC, but this is the only software issue I've encountered so far and the OS is a clean install.
Program may be hang if you use antivirus or windows defender. Please disable it and try again
Related
I am using Code::Blocks 16.01 for coding in C++ every code runs properly without showing any problem or error. But ever I runs a graphics program it shows a pop-up window with message circle.exe has stopped working(circle.cpp is the name of my program)(had already copied graphics.h ,winbigim.h and libbgi.a and also corrected the line 302 error in graphics.h and had also had done the linking work).
code that i am using is:-
//circle.cpp
#include <graphics.h>
int main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm," ");
circle(100,100,50);
getch();
closegraph();
return 0;
}
it shows a pop-up window with message circle.exe has stopped working.
But when ever I run the same code in Turbo C++ it runs without any problem/error.
What should I do?
It is because the BGI graphics expect powers that modern systems don't give out willy-nilly anymore.
To use the old library, your options are:
(1) Run your program in DosBox, and x86 emulator
Dos Box
The other option are to get a modern graphics library, like SDL(It's better way and I suggest you).
so I just installed vs2015, and I'm having issues starting a project. For my intro school programming class, we are learning with the win32 console. I started up my own project at home so I could work on my projects at home, but I'm having issues starting. Thanks in advance for any help. Link to image
Your issue is annoying yet simple to fix, before I answer it you're using visual studio 2015 which means by default you would have been "given " a header file and your main would have looked like the following.
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}
You can modify the main function, as in remove every thing but int main() but I would suggest not doing this.
The answer to your question is, your program will not compile because you are not using #include "stdafx.h"
simply put that in and your projects will work assuming you code them right...
Also after looking at your picture more closely ( next time post your code here)
I see that your only source file showing is named R4.Que? Rename it R4.cpp
When I use string variables in Eclipse CDT (MinGW compiler) and I run the program, it doesn't show me anything. Here's my code:
#include <iostream>
using namespace std;
int main() {
string hw = "Hello, world!";
cout << hw << endl;
return 0;
}
So that doesn't show anything, but when I just do cout << "Hello, world!" << endl; it does work.
I also tried including <string>, <string.h>, "string" and "string.h" but still no success. The same code does work in VC++ and Codeblocks though.
I can reproduce this problem on my machine. The output does not appear. But it is not an output problem, but actually two problems before you get to main:
The program is failing to launch. If you try double-clicking on it in Windows Explorer, you will get an error message like this:
The program can't start because libgcc_s_dw2-1.dll is missing from
your computer. Try reinstalling the program to fix this problem.
Screenshot of above:
When launched from within Eclipse, this error message is silently swallowed, so how are you supposed to know!
Solutions/Workarounds
You need to get the environment correctly set up to launch the MinGW program because its DLLs are not installed on Windows PATH or other standard places DLLs are searched for.
Add C:\MinGW\bin to your PATH
Launch Eclipse from within a MinGW shell (has basically same effect as 1)
Run the program in debug mode, this causes the program to be launched as a child of GCC and that sets up
Other options (not tried by me) may include statically linking the offending library, see The program can't start because libgcc_s_dw2-1.dll is missing
File a CDT bug about the error message being hidden.
Extra info
If your program compiles, as I am sure it does based on your comments, changing the includes is probably irrelevant.
By adding an infinite loop around the couts I could immediately identify something more than simply an output not being shown was going on. Try the same thing on your machine, and also try running the program from within MinGW shell and from outside it.
This question already has answers here:
Launch Failed Binary not found Eclipse for C in Windows
(15 answers)
Closed 9 years ago.
I was trying my first c program in eclipse. Now after installing the c/c++ plugin i have c/c++ perspective.
But when I tried to run this simple C code, a window pops up titled "Application
Launcher", and it contains the following message: "Launch failed.Binary not found".
Please let me know if the mistake in the c code I wrote or in any something else.
C code:
#include <iostream.h>
main() {
cout<<"Hello world!\n";
}
the code you put is C++ code and not C code.
with Eclipse you have first to create new project:
File --> New --> C++ Project --> Executable --> Emptyproject
Give a name to your project and then continue the setting till finish the creation of the project
Edit your C++ source code and then build your project with
Project --> Build All
And then run your binary with the famous green button. or with:
Run --> Run
Correct C++ code is
#include <iostream>
int main() {
std::cout<<"Hello world!\n";
}
Note it's <iostream> not <iostream.h>, std::cout not cout, and int main not main. These mistakes seem to indicate you are learning C++ from a very out of date source.
That's not C; it's an ancient dialect of C++, which a modern compiler will probably reject even if you don't try to build it as C.
A "hello world" in C might look like:
#include <stdio.h>
int main() {
printf("Hello world!\n");
}
and in this century's dialects of C++:
#include <iostream>
int main() {
std::cout << "Hello world!\n";
}
Now you should decide whether to learn C or C++ (which are very different languages), and find a good book on the subject. For C++, start here.
This code:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!\n";
return 0;
}
when comiled give size 457KB in Code::Blocks with GCC 4.4.1 and only 8KB (eight) in VS2010. Both compilers optimized for size.
Anyone knows why such a difference?
This is due to the c++ standard library being linked statically by g++, whereas VS will link it dynamically. A quick check using gcc under cygwin gives me approximately same sizes, and the resulting exe only import some C functions.
#include <stdio.h>
int main() {
printf("Hello world\n");
return 0
}
On the other hand, this application compiled to the same minimal EXE under gcc, as it does not require any c++ functionality.
You are right, the executable by gcc is obviously larger, in your case 57 times larger than that built by vc++.
The main reason is the one made with
GCC won't require any external
dependencies to run while the one made
with VS2010 would need at least its runtime
files to be present on the system.
For instance, say you try it on some friend's computer with no vs2010 installed, rather try earlier OS like XP with no chance of having VS2010 runtimes even.
The one built with GCC will have no problems while the one made with VS2010 would throw an error of missing runtime file ( dependency ).
Hope this helped, if it didn't or you have any other question in your mind, feel free to ask and I'll be glad to help :)