【问题标题】:C++ Compile Error, Help Needed - ld: symbol(s) not found for architecture x86_64C++ 编译错误,需要帮助 - ld:未找到架构 x86_64 的符号
【发布时间】:2013-08-08 22:29:26
【问题描述】:

我正在尝试编译它,但每次我去编译 main.cpp 时都会遇到同样的错误:

Undefined symbols for architecture x86_64:
  "tlogic::tlogic()", referenced from:
      _main in ccAcayG4.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status

我尝试调试了一段时间,但错误似乎仍然存在。任何帮助,将不胜感激。

这里是 main.cpp:

#include <iostream>
using namespace std;

#include "tlogic.h"

int main()
{
        tlogic test;

        exit(EXIT_SUCCESS);
}

tlogic.h:

#ifndef TLOGIC_H
#define TLOGIC_H

class tlogic {
public:
        tlogic();
        tlogic(bool);
        ~tlogic();
        void init();
        void get_command();

private:
        bool debug;
};

#endif

最后是 tlogic.cpp:

#include <iostream>
using namespace std;

#include "tlogic.h"

tlogic::tlogic()
{
        cout << "Testing" << endl;
        debug = false;
}

tlogic::tlogic(bool debug_)
{
        cout << "Testing 2" << endl;
        debug = debug_;
}

tlogic::~tlogic()
{
}

void tlogic::game_init()
{
}

void tlogic::get_command()
{
}

感谢您的帮助。

编辑:修复了 tlogic::glogic 等。

【问题讨论】:

  • 尝试一些更简单的东西。一个简单的“hello world”会编译和链接吗?
  • 编译器抱怨“glogic::glogic()”但是你现在没有这样的类。似乎 main.o 在一些重命名后没有重新编译。尝试清理项目并从头开始构建它。
  • 不。即使您将课程带走并仅在头文件中声明 hello_world() ,它也会给出相同的错误。 hello_world() 在 tlogic.cpp 中定义,但看起来编译器没有链接文件。
  • tlogic::~glogic() 绝对不应该编译。
  • glogic 是一个错误......它已在我的代码中修复,抱歉。在帖子中进行了编辑。

标签: c++ compiler-errors g++


【解决方案1】:

你需要:

g++ -o prog main.cpp tlogic.cpp

当您在一个步骤中进行编译和链接时,您需要确保将制作完整程序所需的所有源文件传递给编译器。

【讨论】:

  • 谢谢。这解决了问题。错过了tlogic.cpp的编译……愚蠢的错误。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-02-21
  • 2015-05-31
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多