【问题标题】:Error when trying to compile C program code in C99 mode尝试在 C99 模式下编译 C 程序代码时出错
【发布时间】:2015-03-21 03:38:41
【问题描述】:

当我编译像“hello world”这样的简单程序时,我在printf 函数处收到警告。 这是错误消息:

hey.c:4:5: warning: implicit declaration of function 'puts' is invalid in C99
  [-Wimplicit-function-declaration]
puts("Hello World!");
^
1 warning generated.
ld: can't write output file: a.out for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

【问题讨论】:

  • 谷歌搜索警告会给你所有你想要的
  • @ArjunSreedharan 这正是我看到问题时所做的
  • 您是在源代码中写了printf(),还是写了puts() 并在写问题时打错了字(您提到printf())。由于消息显示puts(),我宁愿认为你写了puts(),但clang 足够聪明,可以将printf("Hello World!\n"); 之类的调用替换为puts("Hello World!");(GCC 也是如此),所以它可能是。

标签: c macos c99


【解决方案1】:

是的,您需要在代码中包含 stdio.h。通常编译器允许您在没有头文件的情况下使用 printf,但它们会生成警告

【讨论】:

    猜你喜欢
    • 2015-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-02
    • 2013-03-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多