[英]I can't build HELLO, WORLD program?
我是新手学习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!
了解NetBeans的设置方式。 失败的编译是:
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
那里有两个目标文件; 一个看起来像你的helloworld.c
的目标文件与main()
,另一个是文件main.c
的目标文件,可能还包含一个main()
程序。
重新定义构建规则,以便不将main.o
链接到可执行文件中。
我知道这是一个旧帖子,但你应该看看项目的源文件。 在那里,NetBeans默认生成2个main.c文件。 擦除其中一个,只留下一个,然后再次尝试构建项目。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.