nmake Makefile 将目标文件放置在单独的目录中

发布于 2024-07-23 09:42:05 字数 487 浏览 2 评论 0原文

我的所有源文件都位于 Source 文件夹中,makefile 位于 Makefile 文件夹中,我希望所有目标文件都放置在 Objects 文件夹中。 这是我正在开发的一个C 项目。 所有这三个文件夹都位于名为 Project 的文件夹中。

项目文件夹包含: 来源 生成文件 对象

我试图找出一种方法让 makefile 从源文件夹编译源代码,我尝试使用:

...
SOURCE_DIR=..\Source
OUTPUT_DIR=..\Objects
.c.obj:
    $(CC) $(SOURCE_DIR)\$*.c /Fo$(OUTPUT_DIR)\$*.obj
...  

但这不起作用,我最终收到一条错误消息,同时说不知道如何制作 myfile.obj

I have all my source files in the Source folder, The makefile is in the Makefile folder and I want all object files to be placed in Objects folder. It is a C project iam working on. All these three folders are in a folder named Project.

Project folder contains:
Source
Makefile
Objects

iam trying to figure out a way to get the makefile to compile source from Source folder, i have tried using:

...
SOURCE_DIR=..\Source
OUTPUT_DIR=..\Objects
.c.obj:
    $(CC) $(SOURCE_DIR)\$*.c /Fo$(OUTPUT_DIR)\$*.obj
...  

but this is not working, i end up with an error message while says dont know how to make myfile.obj

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

蹲墙角沉默 2024-07-30 09:42:05

试试这个:

SOURCE_DIR=..\Source
OUTPUT_DIR=..\Objects
{$(SOURCE_DIR)}.c{$(OUTPUT_DIR)}.obj:
    $(CC) $* /Fo
lt;

如下所述:http://msdn.microsoft.com/en-我们/library/hk9ztb8x.aspx

Try this:

SOURCE_DIR=..\Source
OUTPUT_DIR=..\Objects
{$(SOURCE_DIR)}.c{$(OUTPUT_DIR)}.obj:
    $(CC) $* /Fo
lt;

As explained here: http://msdn.microsoft.com/en-us/library/hk9ztb8x.aspx

初与友歌 2024-07-30 09:42:05

您应该添加目标,将当前目录更改为您想要创建目标文件的目录。 nmake 示例 Makefile 文件如下。 在示例中,nmake 从当前目录编译 ac bc 并将 objs $(OBJ_FILES_DIR) 目录放置在 $(OUTDIR) 目录中,并在 $(OUTDIR) 目录中构建 SOME_STATIC.LIB。

# commmand to launch Makefile
nmake OBJ_FILES_DIR=my_obj_dir OUTDIR=my_lib_dir

# Makefile
STATICLIB = SOME_STATIC.LIB
OBJS = a.obj b.obj # objs in lib
O = $(OBJ_FILES_DIR)
S = $(MAKEDIR)  # remember source dir where a.c b.c reside and current    dir from which nmake launched.

.PHONY: $(STATICLIB)
.PHONY: CHDIR

$(STATICLIB): CHDIR $(OUTDIR)$(STATICLIB) # 

CHDIR:
    -md $(O) 
    cd $(O)

all: $(STATICLIB) 

$(OUTDIR)$(STATICLIB): $(OBJS)
    $(AR) $(ARFLAGS) -out:$@ $(OBJS)

{$(S)}.c.obj::
    $(CC) $(WFLAGS) $(CFLAGS) -c 
lt;

You should add target, changed the current directory to a directory where objective files you want to be made. The nmake sample Makefile file follows. In sample nmake compiles a.c b.c from current directory and places objs $(OBJ_FILES_DIR) directory and builds a SOME_STATIC.LIB in $(OUTDIR) directory.

# commmand to launch Makefile
nmake OBJ_FILES_DIR=my_obj_dir OUTDIR=my_lib_dir

# Makefile
STATICLIB = SOME_STATIC.LIB
OBJS = a.obj b.obj # objs in lib
O = $(OBJ_FILES_DIR)
S = $(MAKEDIR)  # remember source dir where a.c b.c reside and current    dir from which nmake launched.

.PHONY: $(STATICLIB)
.PHONY: CHDIR

$(STATICLIB): CHDIR $(OUTDIR)$(STATICLIB) # 

CHDIR:
    -md $(O) 
    cd $(O)

all: $(STATICLIB) 

$(OUTDIR)$(STATICLIB): $(OBJS)
    $(AR) $(ARFLAGS) -out:$@ $(OBJS)

{$(S)}.c.obj::
    $(CC) $(WFLAGS) $(CFLAGS) -c 
lt;
做个ˇ局外人 2024-07-30 09:42:05

如果它的字面意思是不知道如何制作myfile.obj,而不是不知道如何制作..\Objects\myfile.obj那么你的问题在其他地方 - makefile 中的某些内容要求当前目录中的目标文件。

需要 myfile.obj 构建的规则是什么? 我猜想在该规则中您未能指定 $(OUTPUT_DIR)\myfile.obj 作为依赖项。

If it is literally saying don't know how to make myfile.obj, and not don't know how to make ..\Objects\myfile.obj then your problem is elsewhere - something in the makefile is asking for an object file in the current directory.

What is the rule that needs myfile.obj to build? I would guess that in that rule you are failing to specify $(OUTPUT_DIR)\myfile.obj as the dependency.

请别遗忘我 2024-07-30 09:42:05

如果您使用 Visual Studio,有时您会收到错误消息:

“不知道如何制作 '.obj'”

我可以通过打开 'Makefile' 并取消注释掉“取消注释”注释下方的行来解决此问题这些在 Visual Studio 2010 中编译时输出 32 位二进制文​​件”。 找到与您的 Visual Studio 版本和体系结构(32 位/64 位)相对应的注释,然后取消注释下面的行!

If you are using Visual Studio, sometimes you get the error message:

"don't know how to make '.obj'"

I was able to solve this by opening 'Makefile' and uncommenting out the lines underneath the comment that says "Uncomment these when compiling in Visual Studio 2010 to output a 32 bit binary". Find the comment that corresponds to your Visual Studio version and your architecture (32-bit/64-bit) and uncomment the lines underneath that!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文