在连接阶段诊断"contains undefined reference for architecture"

Diagnosing "contains undefined reference for architecture" at linking phase

本文关键字:contains undefined reference architecture for 诊断 连接 段诊断      更新时间:2023-10-16

我正在尝试使用qmake/qt在MacOSX上构建一个x86_64应用程序。我能够在QT4中编译,但不能在QT5中编译。

无论如何,在运行qmake生成我的makefile etc:之后

qmake-recursive-spec macx clang app.pro CONFIG+="释放静态"

然后当我运行make时,最终我会出现在这里:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -headerpad_max_install_names -arch x86_64 -Wl,-dead_strip -framework Cocoa -framework Carbon -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -mmacosx-version-min=10.6 -o (...author's note--tons of .o files here...) -L../lib -L../../debug -F/Users/seth/workspace/qt5.1.0//5.1.0/clang_64/lib -lprotobuf -framework Security -framework SecurityInterface -framework ApplicationServices -framework CoreFoundation -lxml2 -lbz2 -lxar -framework ScriptingBridge -L/Users/seth/workspace/qt5.1.0//5.1.0/clang_64/plugins/iconengines -lssl -lcrypto -lz -lFLAC -framework Carbon -framework QtWebKitWidgets -framework QtQuick -framework QtQml -framework QtNetwork -framework QtCore -framework QtGui -framework QtOpenGL -framework QtWidgets -framework QtPrintSupport -framework Cocoa -framework QtWebKit -framework QtSql -framework QtSensors -framework QtSvg -framework QtXml -framework OpenGL -framework AGL

ld: '__ZN3Log16DebugE7QStringS3_' in debug/Log.o contains undefined reference for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

我不明白"体系结构x86_64的未定义引用"是什么意思,这当然是问题的核心。在阅读其他一些线程后,有些线程认为我链接的库不是x86_64,但经过检查和重新检查,我找不到任何非x86_66库参与该过程。

使用file命令进行检查后,构建中的所有.o文件都是Mach-O 64-bit object x86_64

对于我尝试引用的所有库(例如libcrypto):

Non-fat file: ../lib/libcrypto.a is architecture: x86_64

当然,所有的mac框架库都支持32/64位。

有人对我如何进一步调试有什么建议吗?

玩了一整天,找到了。

链接抱怨的方法有这样的:

qt_mac_execute_apple_script

qt5中不存在此方法。

此外,在问题文件的前面,我有这样的:

extern bool qt_mac_execute_apple_script(const QString &script, AEDesc *ret);

如果我对这些行进行注释,错误就会消失。

因此,基本上,对于一个丢失的符号来说,这是一个非常糟糕的编译器错误——因为编译器不够好,无法指出模糊的体系结构声明之外的实际问题;可能会变得更糟,因为我正在构建与extern静态耦合的应用程序。