c++ - 构建简单 Qt5 应用程序时出错

标签 c++ qt build qt-creator qt5

我在 Mac OS X 10.7 上安装了 Qt 5.0.0 (qt-mac-opensource-5.0.0-clang-offline.dmg)。 5 现在我正在尝试使用 Qt Creator 2.6.1 编译“Hello World”应用程序。

构建过程提示找不到目录:/Users/karlphillip/Qt5.0.0/5.0.0/clang_64/qtbase/lib,随后出现几个链接错误:

clang++ -c -pipe -mmacosx-version-min=10.6 -O2 -Wall -W -fPIE -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/Users/karlphillip/Qt5.0.0/5.0.0/clang_64/mkspecs/macx-clang -I. -I/Users/karlphillip/Qt5.0.0/5.0.0/clang_64/include -I/Users/karlphillip/Qt5.0.0/5.0.0/clang_64/include/QtGui -I/Users/karlphillip/Qt5.0.0/5.0.0/clang_64/lib/QtGui.framework/Versions/5/Headers -I/Users/karlphillip/Qt5.0.0/5.0.0/clang_64/include/QtCore -I/Users/karlphillip/Qt5.0.0/5.0.0/clang_64/lib/QtCore.framework/Versions/5/Headers -I. -I/System/Library/Frameworks/OpenGL.framework/Versions/A/Headers -I/System/Library/Frameworks/AGL.framework/Headers -o main.o main.cpp
clang++ -headerpad_max_install_names -mmacosx-version-min=10.6 -o hello_qt.app/Contents/MacOS/hello_qt main.o -F/Users/karlphillip/Qt5.0.0/5.0.0/clang_64/lib -framework QtGui -F/Users/karlphillip/Qt5.0.0/5.0.0/clang_64/qtbase/lib -framework QtCore -framework OpenGL -framework AGL
ld: warning: directory not found for option '-F/Users/karlphillip/Qt5.0.0/5.0.0/clang_64/qtbase/lib'
Undefined symbols for architecture x86_64:
"QApplication::QApplication(int&, char**, int)", referenced from:
_main in main.o
"QLabel::QLabel(QString const&, QWidget*, QFlags<Qt::WindowType>)", referenced from:
_main in main.o
"QWidget::show()", referenced from:
_main in main.o
"QPushButton::QPushButton(QString const&, QWidget*)", referenced from:
_main in main.o
"QApplication::exec()", referenced from:
_main in main.o
"QPushButton::~QPushButton()", referenced from:
_main in main.o
"QLabel::~QLabel()", referenced from:
_main in main.o
"QApplication::~QApplication()", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [hello_qt.app/Contents/MacOS/hello_qt] Error 1

重要的是要注意路径 /Users/karlphillip/Qt5.0.0/5.0.0/clang_64/qtbase/lib 无效,因为目录 qtbase 不'存在。工作路径是/Users/karlphillip/Qt5.0.0/5.0.0/clang_64/lib。我在项目中的任何地方都没有提到 qtbase,所以这可能是由 qmake 添加的。

最佳答案

事实证明,无效的 qtbase 路径实际上是一个 Qt 错误,最初报告于 QTBUG-28336 .

链接问题是由于我的项目没有与 QtWidgets 链接,这是我们从 Qt5 开始必须做的事情。这是通过将以下行添加到您的 .pro 文件来完成的:

QT += widgets

关于c++ - 构建简单 Qt5 应用程序时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14479468/

相关文章:

c++ - 有没有更简单的方法从 QList<Class*> 转换为 QList<QPointer<Class>>?

QThreads 与 Pthreads

qt - 需要如何使qt在Windows上进行静态编译的更新版本

javascript - 如何将对象传递给 gulp 任务以便能够同步运行该任务?

c++ - 跨平台构建库而不运行所有平台

c++ - 如何比较两个充满类的 STL 列表

qt - QML:如何通过拖放重新排序转发器项目?里面有些工作代码

python - 如何使用一片 QSqlQueryModel?

C++编译问题

c++ - 如何在 Visual Studio 中更改 C++ 标准库实现