使用 GCC 编译 C 失败

Failing to compile C using GCC

我正在尝试按照 this NanoPi Neo 指南中的说明编译 test.c。但是,每当我尝试 运行 gcc 命令进行编译时,我都会收到此错误消息...

GNU ld (GNU Binutils for Ubuntu) 2.26.1
  Supported emulations:
   armelf_linux_eabi
   armelfb_linux_eabi
/usr/lib/gcc/arm-linux-gnueabihf/5/../../../arm-linux-gnueabihf/crt1.o: In function `_start':
(.text+0x28): undefined reference to `main'
collect2: error: ld returned 1 exit status

...命令...

sudo gcc -Wall -o test.c -lwiringPi -lpthread -Wl,-V

...以及我正在尝试编译的代码...

#include <wiringPi.h>
int main(void)
{
  wiringPiSetup() ;
  pinMode (7, OUTPUT) ;
  for(;;)
  {
    digitalWrite(7, HIGH) ;
    delay (500) ;
    digitalWrite(7,  LOW) ;
    delay (500) ;
  }
}

我猜这可能是链接问题?我只是不确定,我真的知道如何改变它。 对于C、Linux之类的话题,我还是比较菜鸟的。 :)

您没有指定任何 .c 源文件,因为 -o 指定输出如 @user3386109 提到的。

sudo gcc -Wall test.c -o output_file_name -lwiringPi -lpthread -Wl,-V