C++ 编译错误,需要帮助 - ld : symbol(s) not found for architecture x86_64

标签 c++ compiler-errors g++

我试图让它编译,但每次我去编译 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);
}

逻辑.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 等

最佳答案

你需要:

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

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

关于C++ 编译错误,需要帮助 - ld : symbol(s) not found for architecture x86_64,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18137271/

相关文章:

maven - 如何在Maven编译期间处理有关Groovy的错误?

c++ - 遍历自定义类的列表

c++ - 使用 C++0x 的 unordered_map

c++ - 有没有办法通过编译器的命令行添加代码?

c++ - 无法在 Mingw-w64 中使用 "uniform_int_distribution",但 "exponential_distribution"可以使用

c++ - 前向 boost::从访问者到另一个访问者的变体

C++ 是 operator!= operator== 定义时自动提供

c++ - 关于对象管理器

c# - 当方法具有 IDictionary 和 IDictionary<TKey, TValue> 的重载时调用不明确

C++:重定向 STDOUT