【问题标题】:makefile.win error while compiling c++ on dev c++在开发 c++ 上编译 c++ 时 makefile.win 错误
【发布时间】:2015-07-09 17:25:03
【问题描述】:

我正在尝试在 dev c++ 中使用我自己定义的头文件运行我的代码。

但是当我编译它时得到这个错误:

25      C:\Users\ali\Desktop\hw2\Makefile.win   recipe for target 'tar.exe' failed

它指向makefile.win中的这一行:

    $(CPP) $(LINKOBJ) -o $(BIN) $(LIBS)

而且我已经将我的文件添加到我的项目中: main.cpp&post.cpp&post.h

这是我的代码(仅限 PostBox 类):

在头文件中:

#include <iostream>
#include <string>
using namespace std;

#ifndef P
#define P
class PostBox{
friend void Send(PostBox);
public:
    int getcount();
    void Count();
    PostBox(string,float,int,Person,Person);
    PostBox();
    void setID(string);
    void setweight(float);
    void setsender(Person);
    void setreceiver(Person);
    void cost();
    string getid();
    Person getsender();
    Person getreceiver();
protected:
    static int count;
    string id;
    float weight;
    int price;
    Person sender;
    Person receiver;
};
 #endif

在我的 cpp 文件中:

#include <iostream>
#include "post.h"
using namespace std;
PostBox::PostBox(string id,float weight,int price,Person sender,Person      receiver)
{
this->count=0;
this->id=id;
this->weight=weight;
this->price=price;
this->sender=sender;
this->receiver=receiver;
} 

【问题讨论】:

  • 链接器没有其他错误信息吗?
  • C:\Users\ali\Desktop\hw2\post.o post.cpp:(.rdata$.refptr._ZN7PostBox5countE[.refptr._ZN7PostBox5countE]+0x0):未定义对`PostBox的引用: :count'
  • 所以你的makefile没有问题。你检查过,你已经实现了PostBox::count 的定义吗?我猜您缺少静态类变量的定义。
  • count 是一个统计变量...不是函数
  • 是的,我说过,你需要定义你在标题中声明的静态类变量。见这里:stackoverflow.com/questions/23767241/…

标签: c++ dev-c++


【解决方案1】:

您缺少static int ::count 的声明。

将这样的内容放入您的 cpp 文件 int PostBox::count = 0。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-11-11
    • 1970-01-01
    • 2023-04-01
    • 2015-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多