Qt 报错:Undefined symbols for architecture arm64

简介: MacBook Pro Apple M1 使用 Qt 6.4.1 的时候碰到的报错,做了不同的尝试,最后解决了这个报错。

Bug:Undefined symbols for architecture arm64,完整的报错信息:

设备:MacBook Pro Apple M1

系统:macOS Ventura 13.0

Qt Creator:Qt Creator 9.0.0 Based on Qt 6.4.1 (Clang 13.0 (Apple), arm64)

Qt:Qt 6.4.0

Undefined symbols for architecture arm64:
  "Player::prepareCallLord()", referenced from:
      vtable for Player in moc_player.o
  "Player::preparePlayHand()", referenced from:
      vtable for Player in moc_player.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Landlords.app/Contents/MacOS/Landlords] Error 1
23:00:12: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project Landlords (kit: Desktop (arm-darwin-generic-mach_o-64bit))
When executing step "Make"

尝试 1:有可能是因为 Qt 版本的原因,项目视频里面是用 5.15.2 的版本。

先试着链接 https://www.cnblogs.com/wqcwood/p/15138983.html 中的方法:

做到 make -j15 这一步的时候报错了;

尝试 2:使用 BrewHome 安装了 Qt 5.15.7,设置 Qt mkspec 路径 /opt/homebrew/opt/qt@5/mkspecs/linux-g++,编译的时候出现报错:

make: *** [scorepanel.o] Error 1
make: *** Waiting for unfinished jobs....
In file included from ../Landlords/userplayer.cpp:1:
In file included from ../Landlords/userplayer.h:4:
In file included from ../Landlords/player.h:4:
In file included from /opt/homebrew/Cellar/qt@5/5.15.7/lib/QtCore.framework/Headers/QObject:1:
/opt/homebrew/Cellar/qt@5/5.15.7/lib/QtCore.framework/Headers/qobject.h:46:10: fatal error: 'QtCore/qobjectdefs.h' file not found
#include <QtCore/qobjectdefs.h>
         ^~~~~~~~~~~~~~~~~~~~~~
1 error generated.
1 error generated.
make: *** [cardpanel.o] Error 1
make: *** [main.o] Error 1
1 error generated.
make: *** [robot.o] Error 1
1 error generated.
make: *** [player.o] Error 1
1 error generated.
make: *** [userplayer.o] Error 1
1 error generated.
make: *** [gamecontrol.o] Error 1
11:46:07: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project Landlords (kit: Desktop (arm-darwin-generic-mach_o-64bit))
When executing step "Make"

尝试 3:询问了一下,认为应该是虚函数没有定义导致的

如果是基类声明了一个虚函数,但是没有为其定义函数体,那么就会出现这个错误;

因此有两个修改的方式:

  • 第一个方法:就是将 Player.h 头文件中的虚函数写成纯虚函数 virtual void prepareCallLord() = 0;,只需要在后面令虚函数等于 0 就是纯虚函数;
  • 第二个方法:在 Player.cpp 源文件中为虚函数定义一个空的函数体;

这样改完之后就能够编译成功了!

目录
相关文章
|
1月前
|
JavaScript
VUE——filemanager-webpack-plugin报错TypeError: Cannot read property 'isFile' of undefined
VUE——filemanager-webpack-plugin报错TypeError: Cannot read property 'isFile' of undefined
30 0
|
2月前
|
定位技术
vue-baidu-map 报错 | map is undefined
vue-baidu-map 报错 | map is undefined
46 1
|
2月前
|
定位技术
vue-baidu-map 报错 | BMap is undefined
vue-baidu-map 报错 | BMap is undefined
59 1
|
2月前
|
JavaScript 前端开发
报错:Cannot read properties of undefined (reading ‘$message‘)解决方法
以上就是解决"Cannot read properties of undefined (reading ‘$message‘)"错误的几种方法,希望对你有所帮助。
1023 0
|
3月前
|
关系型数据库 MySQL Serverless
函数计算操作报错合集之当遇到“Cannot read properties of undefined(reading 'props')”错误,该怎么处理
在使用函数计算服务(如阿里云函数计算)时,用户可能会遇到多种错误场景。以下是一些常见的操作报错及其可能的原因和解决方法,包括但不限于:1. 函数部署失败、2. 函数执行超时、3. 资源不足错误、4. 权限与访问错误、5. 依赖问题、6. 网络配置错误、7. 触发器配置错误、8. 日志与监控问题。
|
3月前
|
SQL 分布式计算 大数据
MaxCompute操作报错合集之执行sql时,出现Cannot read properties of undefined (reading 'start')错误提示,该怎么办
MaxCompute是阿里云提供的大规模离线数据处理服务,用于大数据分析、挖掘和报表生成等场景。在使用MaxCompute进行数据处理时,可能会遇到各种操作报错。以下是一些常见的MaxCompute操作报错及其可能的原因与解决措施的合集。
|
3月前
|
Windows
Qtdesigner报错:This application failed to stat could not find or load the Qt platform plugin “windows“
Qtdesigner报错:This application failed to stat could not find or load the Qt platform plugin “windows“
|
4月前
|
Swift
use_frameworks引起的Undefined symbols for architecture arm64
use_frameworks引起的Undefined symbols for architecture arm64
45 0
|
4月前
|
iOS开发
部分库不支持32位系统archive报错:Undefined symbols for architecture armv7
部分库不支持32位系统archive报错:Undefined symbols for architecture armv7
36 0
|
3月前
|
前端开发 小程序 JavaScript
微信小程序-Unhandled promise rejection TypeError: Cannot read property ‘get‘ of undefined
微信小程序-Unhandled promise rejection TypeError: Cannot read property ‘get‘ of undefined