【问题标题】:Error about a class I don't even have关于我什至没有的课程的错误
【发布时间】:2014-12-05 21:40:29
【问题描述】:

这是我的错误

"/Library/Developer/CommandLineTools/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf "/Library/Developer/CommandLineTools/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-MacOSX/practice3 make[2]: * 没有规则来制作目标 newClass.cpp', needed bybuild/Debug/GNU-MacOSX/newClass.o'。停止。 make[1]: * [.build-conf] 错误 2 make: *** [.build-impl] 错误 2

在制作这个程序前几分钟,我偶然创建了一个名为 newClass 的课程,但后来我删除了它,我在我的计算机 (mac) 上根本找不到它。

这是我的程序,如果它完全造成此错误消息,我认为它根本不应该这样做,因为它根本没有调用 newClass 类。

ma​​in.cpp

    #include <iostream>
#include "Birthday.h"
#include "People.h"

using namespace std;

int main() {

    Birthday birthObj(1,28,2000);

    People sebA("Sebastian A", birthObj);
    sebA.printInfo();


}

Birthday.h

#ifndef BIRTHDAY_H
#define BIRTHDAY_H
using namespace std;

class Birthday {
public:
    Birthday(int m, int d, int y);
    void printDate();
private:
    int month;
    int day;
    int year;

};

#endif  

Birthday.cpp

#include "Birthday.h"
#include <iostream>
using namespace std;


Birthday::Birthday(int m, int d, int y) {
    month = m;
    day = d;
    year = y;

}

void Birthday::printDate() {
    cout << day << "/" << month << "/" << year << endl;
}

People.h

#ifndef PEOPLE_H
#define PEOPLE_H

#include <string>
#include "Birthday.h"
using namespace std;

class People {
public:
    People(string x, Birthday bo); 
    void printInfo();
private:
    string name;
    Birthday dateOfBirth; // dateOfBirth is an object

};

#endif

People.cpp

#include <iostream>
#include "Birthday.h"
#include "People.h"
using namespace std;

People::People(string x, Birthday bo)
: name(x), dateOfBirth(bo)
{


}

void People::printInfo(){
    cout << name << " was born on ";
    dateOfBirth.printDate();
}

【问题讨论】:

  • 这是一个生成文件问题。你是 c++ 对我们没用。
  • 啊好吧,你要我补充什么?
  • 不知道,Netbeans 的某种配置,但我不使用 Netbeans。
  • 哦,对了,我去看看Netbeans的选项,谢谢:)
  • 我找不到它,如果其他人可以帮助我。我将不胜感激:)

标签: c++ ios macos class netbeans


【解决方案1】:

make clean 可能会修复它。或者至少只是明确地rm build/Debug/GNU-MacOSX/newClass.o

基本上,当你创建你的类并编译时,你会得到一个 .o ,这取决于它。但是一旦你删除了这个类,你的 makefile 中可能会有一些规则,比如

%.o : %.c
    $(CC) ...

所以make 正在尝试构建newClass.o,它依赖于不存在的newClass.cpp,因此您没有创建它的规则,因此出现错误。如果您只是删除现在不需要的目标文件,那么一切都应该顺利编译。

【讨论】:

  • 是的!现在可以工作了,非常感谢 :) 是一个非常愚蠢的错误,我不知道如何修复。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-09-16
  • 1970-01-01
  • 1970-01-01
  • 2023-03-13
  • 1970-01-01
  • 1970-01-01
  • 2020-10-10
相关资源
最近更新 更多