【问题标题】:Creating Makefiles for VC++ with more than one cpp file使用多个 cpp 文件为 VC++ 创建 Makefile
【发布时间】:2013-06-03 12:35:16
【问题描述】:

我的任务是从教科书中改编一个样板制作文件以用于我的项目。我有 3 个源文件,Item.cpp Main.cpp 和 Item.h,当然还有 makefile。

我相信我的 make 文件无法正常运行的原因是有多个源文件,而示例只有一个 (Assignment1.cpp),这是生成的错误消息。

Microsoft (R) Program Maintenance Utility Version 11.00.51106.1
Copyright (C) Microsoft Corporation.  All rights reserved.

NMAKE : fatal error U1073: don't know how to make 'Assignment01.obj'
Stop.

我查看了一些关于 make 文件的信息,但大多数 C++ 与 g++ 相关,似乎没有人真正使用 make 文件,只是让他们的 IDE 处理它。

# Assignment01 makefile

!include <"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Include\win32.mak">
# !include <win32.mak> for Visual Studio 2010 or earlier
# Visual Studio 2012 may install this file inside C:\Program Files folder

all: Assignment01.exe

.cpp.obj:
  $(cc) $(cdebug) $(cflags) $(cvars) $*.cpp

Assignment01.exe: Assignment01.obj
  $(link) $(ldebug) $(conflags) -out:Assignment01.exe Assignment01.obj $(conlibs) 

【问题讨论】:

    标签: c++ makefile visual-c++


    【解决方案1】:

    您在这里面临的问题是您没有源文件“Assignment01.cpp”,但相应的 .obj 文件已在您的 makefile 中列出。好像你有两个源文件。因此,只需在链接语句中列出两个对应的目标文件 (Item.obj Main.obj)。

    示例如下:

    Assignment01.exe: Item.obj Main.obj
      $(link) $(ldebug) $(conflags) -out:Assignment01.exe Item.obj Main.obj $(conlibs) 
    

    您需要在您的环境中验证这一点。我刚刚输入了这个。

    祝你好运。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-09
      • 2012-12-23
      • 1970-01-01
      相关资源
      最近更新 更多