生成一些但不是全部.o文件的Makefile

生成一些但不是全部.o文件的Makefile,makefile,Makefile,我的makefile正在生成5/7.o文件。知道为什么它拒绝输入entry.o和productiondb.o吗?注意:entry.cpp和production.cpp都存在于文件中 asgmt01: showreport.o entry.o reporter.o productiondb.o stationdata.o yeardata.o resourcecount.o entry.h reporter.h productiondb.h stationdata.h yeardata

我的makefile正在生成5/7.o文件。知道为什么它拒绝输入entry.o和productiondb.o吗?注意:entry.cpp和production.cpp都存在于文件中

      asgmt01: showreport.o entry.o reporter.o productiondb.o stationdata.o yeardata.o resourcecount.o entry.h reporter.h productiondb.h stationdata.h yeardata.h resourcecount.h
           g++ showreport.o entry.o reporter.o productiondb.o stationdata.o yeardata.o resourcecount.o -g -Wall -o asgmt01

      entry.o:  entry.h

      reporter.o:  reporter.h

      productiondb.o:  productiondb.h

      stationdata.o:  stationdata.h

      yeardata.o:  yeardata.h

      resourcecount.o: resourcecount.h

      .PHONY: x
      x:           #cleanthe directory
           rm -f *.o asgmt01
应该进行编译,但我得到以下结果:

制造

g++-c-o showreport.o showreport.cpp

g++-c-o reporter.o reporter.cpp

g++-c-o stationdata.o stationdata.cpp

g++-c-o yeardata.o yeardata.cpp

g++-c-o resourcecount.o resourcecount.cpp

g++showreport.o entry.o reporter.o productiondb.o stationdata.o yeardata.o resourcecount.o-g-Wall-o asgmt01

g++:错误:entry.o:没有这样的文件或目录

g++:错误:productiondb.o:没有这样的文件或目录

make:**[asgmt01]错误1

  update:

  asgmt01: productiondb.o stationdata.o yeardata.o resourcecount.o entry.o reporter.o showreport.o productiondb.h stationdata.h yeardata.h resourcecount.h entry.h reporter.h
        g++ productiondb.o stationdata.o yeardata.o resourcecount.o entry.o reporter.o showreport.o -g -Wall -o asgmt01
  productiondb.o:  productiondb.cpp productiondb.h
        g++ -g productiondb.cpp productiondb.h -o productiondb.o
  stationdata.o:  stationdata.cpp stationdata.h
        g++ -g stationdata.cpp stationdata.h -o stationdata.o
  yeardata.o:  yeardata.cpp yeardata.h
        g++ -g yeardata.cpp yeardata.h -o yeardata.o
  resourcecount.o: resourcecount.cpp resourcecount.h 
        g++ -g resourcecount.cpp resourcecount.h -o resourcecount.o
  entry.o:  entry.cpp entry.h
        g++ -g entry.cpp entry.h -o entry.o
  reporter.o:  reporter.cpp reporter.h
        g++ -g reporter.cpp reporter.h -o reporter.o
  showreport.o: showreport.cpp
        g++ -g showreport.cpp -o showreport.o
  .PHONY: x
  x:           #cleanthe directory
        rm -f *.o asgmt01
结果:

g++-g productiondb.cpp productiondb.h-o productiondb.o

/usr/lib/。/lib64/crt1.o:在函数“u start”中:

/home/abuild/rpmbuild/BUILD/glibc-2.18/csu/。/sysdeps/x86_64/start.S:118:未定义对“main”的引用

/tmp/cc95fNHG.o:在函数'productiondb::productiondb()'中:

/home/student/matthew.cole3/cs261/production/productiondb.cpp:9:StationData::StationData()的未定义引用

/home/student/matthew.cole3/cs261/production/productiondb.cpp:9:StationData::~StationData()的未定义引用

/tmp/cc95fNHG.o:在函数“productiondb::~productiondb()”中:

/home/student/matthew.cole3/cs261/production/productiondb.cpp:17:StationData::~StationData()的未定义引用

/tmp/cc95fNHG.o:在函数“productiondb::addData(entry const&)”中:

/home/student/matthew.cole3/cs261/production/productiondb.cpp:24:StationData::add(entry const&)的未定义引用

/home/student/matthew.cole3/cs261/production/productiondb.cpp:27:StationData::add(entry const&)的未定义引用

/home/student/matthew.cole3/cs261/production/productiondb.cpp:30:StationData::add(entry const&)的未定义引用

/home/student/matthew.cole3/cs261/production/productiondb.cpp:33:StationData::add(entry const&)的未定义引用

/home/student/matthew.cole3/cs261/production/productiondb.cpp:36:StationData::add(entry const&)的未定义引用

/tmp/cc95fNHG.o:/home/student/matthew.cole3/cs261/production/productiondb.cpp:39:下面是对“StationData::add(entry const&)”的更多未定义引用

collect2:错误:ld返回了1个退出状态


make:**[productiondb.o]错误1

通常,Makefile的每个条目都应该提供build命令,如下所示:

entry.o: entry.cpp entry.h
    g++ -c $< -o $@
entry.o:entry.cpp entry.h
g++-c$<-o$@

变量
$似乎解决了这个问题,但现在不管顺序如何,第一个.o文件都会出错,并说“未定义对main的引用”,您可以发布更新的Makefile吗?如果你有
g++-c
,它不应该关心main…谢谢。错误源于在
g++
命令中包含
.h
文件。例如,在新的Makefile中,您已经编写了
g++-c entry.cpp entry.h…
而不是使用获得它的
g++-c$!谢谢,特雷弗!令人惊叹的你介意接受原来的答案吗?