【问题标题】:Why does 'printf' print nothing in gcc?为什么'printf'在gcc中什么都不打印?
【发布时间】:2020-01-10 06:31:52
【问题描述】:

所以,本质上,我正在尝试制作一个打印“Hello, World!”的简单程序。到输出,但它实际上什么都不做,没有错误或任何东西。

这是我的代码:

#include <stdio.h>

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

这是我用来运行它的命令;

gcc runtime.c

另外,gcc -v 命令。

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)

它应该打印出“Hello, World”,但这就是它所做的一切:

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

如果有人能提供帮助,那对我来说意义重大,谢谢!

【问题讨论】:

  • gcc runtime.c 只编译程序。它不会尝试执行它。您需要自己执行编译后的代码。 (您应该养成用换行符终止打印行的习惯,否则您会遇到其他问题。但这不是这里的问题。)
  • 你刚刚编译了程序。现在运行它!由于您在 Windows 下,我猜该应用程序将是 a.exe。运行那个可执行文件!
  • @PhoenixBlue 我不熟悉 gcc 但输出不会是runtime.exe
  • @CareyGregory:在类 UNIX 系统上,默认值为 a.out(最初的意思是“汇编器输出”)。在 Windows 上,它通常是 a.exe。更好的是,不要依赖默认值:gcc runtime.c -o runtimegcc runtime.c -o runtime.exe

标签: c gcc printf


【解决方案1】:

你不是在运行代码,你只是在编译它。

您给它的命令会创建一个名为a.exe 的可执行文件。编译完成后,运行可执行文件。

a.exe

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-08
    • 1970-01-01
    • 2014-02-16
    • 1970-01-01
    • 2021-08-21
    • 2021-10-23
    相关资源
    最近更新 更多