“未定义对”的引用在G ++ Cpp [英] "undefined reference to" in G++ Cpp

查看:161
本文介绍了“未定义对”的引用在G ++ Cpp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎无法让错误消失。错误如下。我已经看了google,仍然不能弄清楚。它不像我是新的Cpp,但没有蠢了它在一段时间。

Can't seem to get the errors to go away. Errors are below. I have looked on google and still can't figure it out. It is not like I am new to Cpp, but have not fooled with it in a while.

很奇怪的是它与G ++在Windows中的工作...

错误:


  • [ze @ fed0r! - - - ** _ _ *] $ g ++ main.cpp

  • /tmp/ccJL2ZHE.o: ':

  • main.cpp :( .text + 0x11):未定义引用`Help :: Help()'

  • main.cpp: (.text + 0x1e):未定义引用`Help :: sayName()'

  • main.cpp :(。 )'

  • main.cpp :( .text + 0x46):未定义引用`Help ::〜Help()'

  • collect2:ld返回1个退出状态

  • [ze@fed0r! ---**__*]$ g++ main.cpp
  • /tmp/ccJL2ZHE.o: In function `main':
  • main.cpp:(.text+0x11): undefined reference to `Help::Help()'
  • main.cpp:(.text+0x1d): undefined reference to `Help::sayName()'
  • main.cpp:(.text+0x2e): undefined reference to `Help::~Help()'
  • main.cpp:(.text+0x46): undefined reference to `Help::~Help()'
  • collect2: ld returned 1 exit status

main.cpp

#include <iostream>
#include "Help.h"

using namespace std;

int main () {

    Help h;
    h.sayName();

    // ***

    // ***

    // ***
    return 0;

}

Help.h

#ifndef HELP_H
#define HELP_H

class Help {
    public:
        Help();
        ~Help();
        void sayName();
    protected:
    private:
};

#endif // HELP_H

Help.cpp

#include <iostream>
#include "Help.h"

using namespace std;

Help::Help() { // Constructor
}

Help::~Help() { // Destructor
}

void Help::sayName() {
    cout << "            ***************" << endl;
    cout << "   ************************************" << endl;
    cout << "              ************" << endl;
    cout << "         *********************" << endl;
}


推荐答案

g ++ main.cpp帮助。 cpp

g++ main.cpp Help.cpp

您必须告诉编译器所有要编译的文件,而不仅仅是第一个。

You have to tell the compiler all the files that you want it to compile, not just the first one.

这篇关于“未定义对”的引用在G ++ Cpp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆