c - 我无法构建 HELLO, WORLD 程序?

标签 c gcc netbeans compiler-errors

我是学习 C 的新手,我在 Windows 上(我想在 Windows 上学习)。

我已经在 cygwin 上安装了 GCC,并且我正在使用 NetBeans IDE

来源:

#include <stdio.h>

main()
{
    printf("Hello, world!\n");
    return 0;
}

我在构建上述代码时遇到了这个错误:

"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/cygdrive/g/VS Projects/Hello World'
"/usr/bin/make"  -f nbproject/Makefile-Debug.mk dist/Debug/Cygwin_4.x-Windows/hello_world.exe
make[2]: Entering directory `/cygdrive/g/VS Projects/Hello World'
mkdir -p build/Debug/Cygwin_4.x-Windows
rm -f build/Debug/Cygwin_4.x-Windows/helloworld.o.d
gcc    -c -g -MMD -MP -MF build/Debug/Cygwin_4.x-Windows/helloworld.o.d -o build/Debug/Cygwin_4.x-Windows/helloworld.o helloworld.c
mkdir -p dist/Debug/Cygwin_4.x-Windows
gcc     -o dist/Debug/Cygwin_4.x-Windows/hello_world build/Debug/Cygwin_4.x-Windows/helloworld.o  build/Debug/Cygwin_4.x-Windows/main.o 
build/Debug/Cygwin_4.x-Windows/main.o: In function `main':
/cygdrive/g/VS Projects/Hello World/main.c:14: multiple definition of `main'
build/Debug/Cygwin_4.x-Windows/helloworld.o:/cygdrive/g/VS Projects/Hello World/helloworld.c:4: first defined here
collect2: error: ld returned 1 exit status
nbproject/Makefile-Debug.mk:63: recipe for target `dist/Debug/Cygwin_4.x-Windows/hello_world.exe' failed
make[2]: *** [dist/Debug/Cygwin_4.x-Windows/hello_world.exe] Error 1
make[2]: Leaving directory `/cygdrive/g/VS Projects/Hello World'
nbproject/Makefile-Debug.mk:60: recipe for target `.build-conf' failed
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory `/cygdrive/g/VS Projects/Hello World'
nbproject/Makefile-impl.mk:39: recipe for target `.build-impl' failed
make: *** [.build-impl] Error 2


BUILD FAILED (exit value 2, total time: 562ms)

有什么简单的方法可以在 Windows 上学习 C 吗?(visual studio 给我错误,似乎主要是针对 c++,所以这不是一个选项)

最佳答案

问题可能出在您的 gcc 或您的 NetBeans 配置上

这里一切正常

// helloworld.c
#include <stdio.h>

main()
{
    printf("Hello, world!\n");
    return 0;
}

编译成myprog

$ gcc helloworld.c -o myprog

运行它

$ ./myprog
# => Hello, world!

关于c - 我无法构建 HELLO, WORLD 程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17710009/

相关文章:

c - c中的程序意外终止

c - 链接库中的函数在可执行文件中看不到

c - Scanf 在 C 中跳过每隔一个 while 循环

linux - SVN 1.7.1 问题

java - 无法在 Netbeans JavaFX 项目中集成使用 SceneBuilder 生成的 FXML

android - 如何在Android.mk的LOCAL_CFLAGS中动态获取当前编译目标文件名?

c - libudev 返回重复的 USB 设备

Java 使用 BeanBinding Netbeans 更新 JList

使用 void(*)(void) 指针调用 void function(int) 并准备使用参数堆栈

gcc - 可以为 clang 或 gcc 配置 constexpr 递归限制吗?