nmake Makefile 将目标文件放置在单独的目录中
我的所有源文件都位于 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
试试这个:
如下所述:http://msdn.microsoft.com/en-我们/library/hk9ztb8x.aspx
Try this:
As explained here: http://msdn.microsoft.com/en-us/library/hk9ztb8x.aspx
您应该添加目标,将当前目录更改为您想要创建目标文件的目录。 nmake 示例 Makefile 文件如下。 在示例中,nmake 从当前目录编译 ac bc 并将 objs $(OBJ_FILES_DIR) 目录放置在 $(OUTDIR) 目录中,并在 $(OUTDIR) 目录中构建 SOME_STATIC.LIB。
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.
如果它的字面意思是
不知道如何制作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 notdon'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.如果您使用 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!