问题描述:

I'm about to start learning C (I need to program something in C, to convert it into MIPS later).

I'm on Windows 8, and downloaded MinGW and set the path variable to its directory, so that the gcc or g++ commands should work in command prompt.

I copied the following Hello World example into a .c text file.

#include<stdio.h>

int main(void)

{ // This is a comment

printf("Hello world!\n");

return 0;

}

However, although I'm in the correct directory as the file, on command prompt when I type "gcc helloWorld.c" it pauses for a couple of seconds, and then doesn't do anything. It just acts as if the program has finished and allows me to type something else in.

This is likely to be a simple mistake - I don't really understand what I'm doing. But can anyone help me out?

网友答案:

When you issue the gcc command you are actually COMPILING the source code, NOT RUNNING the program. The Compiling process creates an executable file to that you can run.

In the example by previuous poster:

gcc -o helloWorld helloWorld.c

The -o parameter is the [o]utput name of the executable file to be created, let say "helloworld.exe" (as you are using Windows). This should create a new file helloworld.exe, Now you can RUN that file.

Should read a little bit more on general C programming and compiling.

网友答案:

You can write comments with // or /* ... */

Also to compile a c program with gcc use this:

gcc -o helloWorld helloWorld.c

So this should work:

#include<stdio.h>

int main(void)
{  // This is a comment
  printf("Hello world!\n");
  return 0;
} 
网友答案:

You can either use:

gcc -o *executablename* *filename.c*

which creates an executable file called executablename or use:

gcc *filename.c*

which will make an executable file with the default name (a.out for UNIX, I'm not sure what it is for Windows). If you look into the directory, you should be able to see this executable.

网友答案:

You can use this command:

gcc helloWorld.c

and after that:

./a.out
相关阅读:
Top