-2

So, essentially, I am trying to make a simple program that prints "Hello, World!" to the output, but it does literally nothing, no errors or anything.

This is my code:

#include <stdio.h>

int main() {
    printf("Hello, World!");
    return 0;
}

And this is the command I use to run it;

gcc runtime.c

Also, the gcc -v command.

Using built-in specs.
COLLECT_GCC=C:\MinGW\bin\gcc.exe
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/8.2.0/lto-wrapper.exe
Target: mingw32
Configured with: ../src/gcc-8.2.0/configure --build=x86_64-pc-linux-gnu --host=mingw32 --target=mingw32 --prefix=/mingw --disable-win32-registry --with-arch=i586 --with-tune=generic --enable-languages=c,c++,objc,obj-c++,fortran,ada --with-pkgversion='MinGW.org GCC-8.2.0-3' --with-gmp=/mingw --with-mpfr=/mingw --with-mpc=/mingw --enable-static --enable-shared --enable-threads --with-dwarf2 --disable-sjlj-exceptions --enable-version-specific-runtime-libs --with-libiconv-prefix=/mingw --with-libintl-prefix=/mingw --enable-libstdcxx-debug --with-isl=/mingw --enable-libgomp --disable-libvtv --enable-nls --disable-build-format-warnings
Thread model: win32
gcc version 8.2.0 (MinGW.org GCC-8.2.0-3)

It should be printing out "Hello, World", but this is all it does:

PS C:\Users\myirlname\Coding\Lunar Language(c)> gcc runtime.c
PS C:\Users\myirlname\Coding\Lunar Language(c)>

If anyone can help, that would mean a lot to me, thanks!

  • 3
    `gcc runtime.c` only compiles the program. It doesn't attempt to execute it. You need to execute the compiled code yourself. (You should get in the habit of terminating printed lines with a newline, otherwise you'll run into other issues. But that's not what the problem here is.) – rici Sep 07 '19 at 22:44
  • 2
    You just compiled the program. now run it! Since you are under windows, I guess the application would be `a.exe`. run that executable! – PhoenixBlue Sep 07 '19 at 22:45
  • @PhoenixBlue I'm not familiar with gcc but wouldn't the output be `runtime.exe`? – Carey Gregory Sep 07 '19 at 22:46
  • When you browse the files in the working directory (where you created your code and compiled), isn't there a `.exe` file? – PhoenixBlue Sep 07 '19 at 22:48
  • Look up the difference between compiling (producing an object file from source), linking (producing an executable file from a set of object and library files), and execution (running the executable). All steps are necessary in order to get the output you expect. `cc runtime.c` only does the first two steps (and you need to find the executable to run it). – Peter Sep 07 '19 at 23:16
  • @CareyGregory The only case where the output file name matches the source file name is if you're using `gcc -c file.c`, in which case the output would be `file.o`. Otherwise, the output will be `a.` (be it `out` or `exe`). Also note that on Windows `.exe` is suffixed if it is not already present in the output executable name. – S.S. Anne Sep 08 '19 at 00:09
  • 2
    @CareyGregory: On UNIX-like systems, the default is `a.out` (which originally meant "assembler output"). On Windows, it's generally `a.exe`. Better yet, don't depend on the default: `gcc runtime.c -o runtime` or `gcc runtime.c -o runtime.exe` . – Keith Thompson Sep 08 '19 at 00:38
  • 1
    Possible duplicate of [How to compile a C program with gcc?](https://stackoverflow.com/questions/45604027/how-to-compile-a-c-program-with-gcc) – phuclv Sep 08 '19 at 04:44
  • there are a lot of duplicates: [When I compile .c file it always creates .exe file with name 'a'](https://stackoverflow.com/q/47305324/995714), [gcc compiler in Cygwin output .exe](https://stackoverflow.com/q/45315025/995714), [Unable to run C program through cmd](https://stackoverflow.com/q/24345974/995714) – phuclv Sep 08 '19 at 04:48

1 Answers1

2

You're not running the code, you're just compiling it.

The command as you've given it creates an executable called a.exe. After compiling, run the executable.

a.exe
S.S. Anne
  • 15,171
  • 8
  • 38
  • 76
dbush
  • 205,898
  • 23
  • 218
  • 273