【问题标题】:Symbol(s) not found for architecture x86_64 (C++) using qt Creator IDE [duplicate]使用qt Creator IDE找不到架构x86_64(C++)的符号[重复]
【发布时间】:2017-03-12 15:53:26
【问题描述】:

我基本上被我想测试的程序之一卡住了,因为我一直收到这个符号未找到错误。

我的程序很简单,在 C++ 方面我是一个极端的初学者,所以我只是想学习一些继承的东西。下面是程序的结构:

The object diagram of the program

所以这很简单,我有 2 个抽象类,即 Vehicle.h 和 MotorVehicle.h , Bus 和 Car 将继承 MotorVehicle.h 的属性 和 Bicycle 将是 Vehicle.h 的后代,因为它不是机动车。

代码和文件非常多,所以如果有人想知道代码,我就把qt项目文件夹留在这里:

https://drive.google.com/open?id=0B1hy9BsfLLwab19wODR2UWhnRmc

现在,由于某种原因,每当我想运行程序时,我都会收到 Symbol(s) not found for architecture x86_64 错误,我检查了 编译输出的 qt Creator,它是这样说的:

Undefined symbols for architecture x86_64:
  "vehicle::MotorVehicle::~MotorVehicle()", referenced from:
  Car::~Car() in main.o
  Bus::~Bus() in main.o
  Car::~Car() in Car.o
  Bus::~Bus() in Bus.o
  "vehicle::Vehicle::~Vehicle()", referenced from:
  Bicycle::~Bicycle() in main.o
  Bicycle::~Bicycle() in Bicycle.o
  "typeinfo for vehicle::MotorVehicle", referenced from:
  typeinfo for Car in Car.o
  typeinfo for Bus in Bus.o
  "typeinfo for vehicle::Vehicle", referenced from:
  typeinfo for Bicycle in Bicycle.o
  "vtable for vehicle::MotorVehicle", referenced from:
  vehicle::MotorVehicle::MotorVehicle(int, int, int, double) in main.o
  vehicle::MotorVehicle::MotorVehicle(int, int, int,    std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, double) in main.o
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
  "vtable for vehicle::Vehicle", referenced from:
  vehicle::Vehicle::Vehicle(int, int, is std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in main.o
  NOTE: a missing vtable usually means the first non-inline virtual member    function has no definition.
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Vehicles] Error 1
02:38:06: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project Vehicles (kit: Desktop Qt 5.8.0 clang 64bit)
When executing step "Make"

我只想说我很困惑,因为我对 C++ 很陌生,我已经尝试从其他 SO 讨论线程中寻找答案,但我只是找不到与我相关的任何内容,所以看起来(或也许我只是还不够努力)

大家好,提前多谢

【问题讨论】:

    标签: c++ qt x86-64


    【解决方案1】:

    您将您的析构函数声明到 Vehicle 类中,virtual ~Vehicle() 但您没有为它提供实现。如果你不想释放任何东西,你应该像这样声明它virtual ~Vehicle() {}。 MotorVehicle 析构函数也是如此。

    “未找到符号”错误非常具有误导性。其实就是说有一个定义好的符号,主要是函数,没有找到它的实现。

    【讨论】:

    • 哦,废话!!!原来如此,哈哈,天哪,非常感谢您抽出宝贵的时间来查看我的代码。我对此非常陌生,我什至不知道析构函数的真正用途是什么,所以我还有很长的路要走。队友的欢呼声!再次,非常感谢! :)
    • 由于您不使用动态内存分配并且您不获取任何资源,因此您实际上不必处理析构函数。尽管如此,了解析构函数很重要:en.cppreference.com/w/cpp/language/destructor
    • 非常感谢伙计,我可能会在周末有空的时候阅读它。干杯~
    猜你喜欢
    • 2018-11-11
    • 2015-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-20
    • 2020-09-09
    • 1970-01-01
    相关资源
    最近更新 更多