如何使用C设置Eclipse以进行大学工作 [英] How to setup eclipse with C for university work

查看:99
本文介绍了如何使用C设置Eclipse以进行大学工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Eclipse很陌生,但是已经想出了如何在 Java 中使用它。

I'm fairly new to eclipse but have figured out how to use it with Java.

但是,我们现在转到C上,我很难使用它。我只想在实验室中使用eclipse-即创建/编译/测试/运行已设置的C练习或任务。

However, we are now moving on to C and I am having a hard time using it. I just want to use eclipse for my labs - i.e. to create / compile / test / run C exercises or tasks that have been set.

我创建了一个新的'Labs'C项目,并正在创建文件 ex1.c ex2.c 等在 src 文件夹中。 Eclipse不喜欢这样做,原因是多个文件中有多个 main ,但是文件没有关联,每个文件都应该有自己的主要

I created a new 'Labs' C project and have been creating the files ex1.c, ex2.c etc in the src folder. Eclipse doesn't like this due to more than one main across multiple files, but the files aren't related and each is supposed to have their own main.

有人可以建议我是否有更好的方法来设置/组织此工作区的工作空间,或者如何一次在Eclipse中编译/运行单个文件?

Can someone advise me as to whether there is a better way to setup / organise my workspace for this labwork or alternatively how to compile / run single files at a time in eclipse?

推荐答案

您有几个选择:


  1. 为每个可执行文件创建一个项目(这些项目可以在同一工作区中)。这是不言自明的,但是如果您有很多可执行文件,则可能会很烦人。另外,如果需要在可执行文件之间共享代码,则必须为共享代码创建一个单独的项目并设置依赖项。

  1. Create one project per executable (the projects can be in the same workspace). This is pretty self-explanatory, but it might get annoying if you have a lot of executables. Also, if you need to share code between your executables, you'd have to create a separate project for the shared code and set up dependencies.

创建一个项目具有多个构建配置,每个可执行文件一个。有关如何操作,请参见此答案

Create one project with multiple build configurations, one per executable. See this answer for how to do that.

使用Eclipse仅用于浏览和编辑代码,并从命令行构建(和运行/调试)可执行文件。这样,Eclipse项目的组织就无关紧要了,您可以根据需要从命令行进行构建(在这个阶段,简单的Makefile可能是最简单的)。

Use Eclipse for navigating and editing your code only, and build (and run/debug) your executables from the command line. This way, the organization of the Eclipse project(s) is irrelevant, and you can build from the command line however you want (at this stage, a simple Makefile is probably the easiest).

我更喜欢第3个选项,但在某种程度上,这是个问题。如果您想做所有事情,包括从IDE进行构建,请选择#1或#2。

I prefer option #3, but to some extent it's a matter of taste; if you like to do everything including building from the IDE, go with #1 or #2.

编辑:一个简单的Makefile可能看起来像这个:

EDIT: A simple Makefile might look like this:

ex1 : src/ex1.c
    gcc -o ex1 src/ex1.c

ex2 : src/ex2.c
    gcc -o ex2 src/ex2.c

...

放入名为 makefile 的文件,然后运行 make 建立。 (如果您使用的是Windows,则可以编写 ex1.exe 而不是仅 ex1 。)

put into a file named makefile, and you would then run make to build. (If you're on Windows you would write ex1.exe instead of just ex1.)

看看类似这个来了解Makefile的工作原理。

Have a look at a tutorial like this one to understand how Makefiles work.

这篇关于如何使用C设置Eclipse以进行大学工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆