NetBeans 中的 .c 文件集合及其 main()
我正在使用 NetBeans 7.0.1 来学习 C。 我已经完成了在 NetBeans 中开始编译的所有先决条件,因此我对此表示同意。 我已经完成了一个带有 main()
的“HelloWorld.c”,它运行良好。但后来我用其各自的 main()
制作了“Another.c”。我收到一个错误,说明我已经声明了 main()
。
如何在同一项目中拥有 .c 文件集合及其各自的 main
?我这样做是因为我在工作中转换了一些角色,因此需要学习该语言。
有没有办法让 NetBeans 可以在没有项目的情况下处理所有 .c?或者我应该在 Visual Studio 2010 中尝试这个?
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 "HelloWorld.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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是每个可执行文件只能有一个
main()
,但您要将这两个文件编译成一个可执行文件。当它链接它们时,它发现它链接在一起的两个文件中都存在main()
函数,因此报告这一点。解决方案是让 netbeans 为每个文件构建两个独立的可执行文件。最简单的方法就是创建两个独立的项目。
还有一种稍微混乱的方法可以在单个 netbeans 项目中完成这项工作,但除非你有令人信服的理由,否则我不会推荐它。另一种解决方法是编写自己的makefile来构建两个二进制文件,而不是使用 netbeans 托管的二进制文件。
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 themain()
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.