2

我正在尝试使用 Eclipse 中的 C 项目生成两个 exe,客户端和服务器。两者都有主要功能,因为它们是不同的 exe。两者都使用一个通用的 confutils.c 文件。如何解决主要问题的多重定义。我知道我们不能在一个项目中拥有两个主电源。我的 makefile 如下所示。

.c.o:
    gcc -g -c $?

# compile client and server
all: confclient confserver

# compile client only
confclient: confclient.o confutils.o
    gcc -g -o confclient confclient.o  confutils.o

# compile server program
confserver: confserver.o confutils.o
    gcc -g -o confserver confserver.o  confutils.o

我用这个替换了eclipse文件。我不知道eclipse是否正确阅读。我不喜欢把这个项目一分为二,因为它是如此简单的程序。我能够在 unix 中毫无问题地运行这些文件。我正在尝试查找 Eclipse 中是否有一个选项,我们可以使用它来设置构建配置。

4

2 回答 2

2

可以定义多个构建配置——每个配置都有不同的构建文件集。

首先打开项目属性并导航到Manage Configurations

在此处输入图像描述

创建一个的构建配置:

在此处输入图像描述

并将其设置为活动

在此处输入图像描述

最后定义过滤器排除文件,以确保您构建一个源文件,main()您只想使用:

在此处输入图像描述

就是这样:

在此处输入图像描述

现在您可以从> > >中选择目标构建配置。MenuProjectBuild ConfigurationsSet Active

于 2016-11-14T08:08:54.240 回答
0

I think you can set up multiple "Build Configurations" to avoid this. Under "Project" in the menu bar you can choose your active build configuration.

There are ways to exclude files in different configurations. Under your project properties you go to "C/C++ General", "Paths and Symbols" and here you choose "Source Location". Top most you can now choose your build configuration and then define different sorurce locations for you different build configurations. Here you add folders for your source code, and, here comes the trick, for the folders you choose to include you can put filter to ignore specific files.

In your case I would make two Build Configurations, one for confclient and for this one I would exclude confserver.c from the scource location, and vice versa.

You will need to build you project twice, but the utilspart will be left unchanged and hence it wont recompile which is a benefit over having two projects. Also it might be nice to have all the code in the same project since I guess the code on the server side and client side will be connected.

于 2014-04-23T15:53:07.230 回答