Macos 如何在mac上构建Qt5项目
我尝试在Mac上构建一个简单的Qt5程序。但我失败了 代码非常简单:Macos 如何在mac上构建Qt5项目,macos,qt,clang,Macos,Qt,Clang,我尝试在Mac上构建一个简单的Qt5程序。但我失败了 代码非常简单: #include <QtWidgets/QApplication> int main(int argc, char *argv[]) { QApplication app (argc, argv); return app.exec(); } 然后我得到了这个错误: Undefined symbols for architecture x86_64: "QApplication::exec()
#include <QtWidgets/QApplication>
int main(int argc, char *argv[])
{
QApplication app (argc, argv);
return app.exec();
}
然后我得到了这个错误:
Undefined symbols for architecture x86_64:
"QApplication::exec()", referenced from:
_main in test-jPGORy.o
"QApplication::QApplication(int&, char**, int)", referenced from:
_main in test-jPGORy.o
"QApplication::~QApplication()", referenced from:
_main in test-jPGORy.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
有什么我遗漏的吗?我也有同样的问题,在我看来,发行版中有某种缺陷,它给了我一些错误,因为在新安装(使用qt creator)后,我没有一些模糊的qt库(不是普通的qt5模块,而是开发中的某种库)所以我倾向于认为这可能是qt的问题 也就是说,我有一些问题需要更好地理解: -您正在使用IDE吗 -如果你用的是哪一种 -您是否将所有模块都包含在*.pro for quake中 -您是否使用过4.8版本,是否遇到过这些问题
另外,如果您没有任何特殊的必要性,我建议您在一段时间内坚持使用4.8版(我这样做没有问题),因为5.0刚刚发布首先,不要手工编译和链接Qt项目;使用qmake和项目文件 在源目录中运行
qmake-project
,以生成基本项目文件
编辑项目文件并添加以下行:QT+=widgets
现在运行qmake
生成一个makefile
现在运行make
来构建您的程序
其次,您可以简单地
#包括如果您想使用clang++支持qmake,则需要指定要链接到的库以及库目录(您提供的)
Undefined symbols for architecture x86_64:
"QApplication::exec()", referenced from:
_main in test-jPGORy.o
"QApplication::QApplication(int&, char**, int)", referenced from:
_main in test-jPGORy.o
"QApplication::~QApplication()", referenced from:
_main in test-jPGORy.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
clang++ -I ~/Qt5.0.0/5.0.0/clang_64/include -L/Users/crazylion/Qt5.0.0/5.0.0/clang_64/lib -lQtCore -lQtGui test.cpp