A .c file collection with their main() in NetBeans
I'm using NetBeans 7.0.1 to learn C.
I have done all the pre-requisites to start compiling in NetBeans so I'm ok with that.
I have done a "Hell开发者_开发问答oWorld.c" with a main()
in it and it runs fine. But then I made "Another.c" with its respective main()
. I got an error which describes that I have already declared a main()
.
How can I have a .c files collection in the same project with their respective main
s? I'm doing this because I require the learning of the language since I switched some roles at work.
Is there a way so NetBeans can handle all the .c without a project? Or should i try this in Visual Studio 2010?
The problem is that you can only have one main()
per executable, but you're compiling the two files into on executable. When it links them it's spotting that the main()
function exists in both of the files it's linking together and consequently reports this.
The solution is to make netbeans build you two, separate executables from each file. The easiest way to do this is to simply make two independent projects.
There is also a slightly messy way of making this work within a single netbeans project, but I wouldn't recommend it unless you have a compelling reason. The other workaround would be to write your own makefile to build two binaries, instead of using the netbeans managed one.
精彩评论