如何用cmake在linux下构建Qt项目
How to build Qt project in linux with cmake
我使用的是ubuntu 14.04, cmake 2.8.12.2, Qt5.6.2(一个构建版本),GNU make 3.81
使用cmake PathToSource -G "Eclipse CDT4 - Unix Makefiles"
运行cmake后
我用make
。我得到#error "You must build your code with position independent code if Qt was built with -reduce-relocations. " "Compile your code with -fPIC (-fPIE is not enough)."
# error "You must build your code with position independent code if Qt was built with -reduce-relocations. "
然后我下载Qt5.7.0
的源文件,构建并安装它没有问题。我再做一次cmake PathToSource -G "Eclipse CDT4 - Unix Makefiles"
,成功了。我得到了很多错误,如/home/sflee/Documents/Software_dev/3rd_party/Qt5.7.0/include/QtCore/qhash.h:957:10: error: ‘pair’ does not name a type
auto pair = qAsConst(*this).equal_range(akey);
和/home/sflee/Documents/Software_dev/3rd_party/Qt5.7.0/include/QtCore/qbasicatomic.h:285:14: error: ‘Ops’ has not been declared
{ return Ops::fetchAndAddRelease(_q_value, valueToAdd); }
如何解决?
Qt 5.7需要c++ 11编译器。如果您从auto pair
中得到这种错误,则听起来您的编译器没有编译c++ 11代码。有两个可能的原因:
-
你只需要将
-std=c++11
传递给你的编译器,正如这个问题所解释的。 -
你的编译器太旧了。然而,因为你用同样的编译器编译了Qt 5.7,这对你来说应该不是问题。
- 如何构建Qt + cmake + QGLWidget
- 在Visual Studio 2017中构建Qt可执行文件
- 尝试使用 MSVC 从源代码构建 qt 创建器:无法打开包含文件:"stddef.h":没有这样的文件或目录
- 错误:无法构建 PhantomJS!构建Qt基地失败
- 如何在构建Qt应用程序时运行git命令
- 使用Visual Studio构建QT
- 如何使用MINGW-W64通过链接时间优化构建QT
- 使用Qt多媒体支持构建Qt
- 尝试在树莓派上构建Qt项目,为什么它会抛出有关qmake的错误
- MSVC 编译器在调试模式下构建 Qt 5.10 时崩溃
- 如何使用-REDUCE -RECATIONS构建QT
- 从MACOS上的源代码构建QT时错误
- 如何有效地构建QT应用程序
- 如何正确构建Qt插件
- 从源代码构建Qt 5.8 - 配置:未知命令行选项'-c++11'
- 尝试使用VC++编译器构建Qt应用程序:"type_traits":没有这样的文件或目录
- 如何使用Team Foundation Server 2017构建QT应用程序
- 使用Visual Studio 2013构建QT 5.2.1的静态版本
- 为嵌入式系统构建QT时错误
- 无法在Visual Studio 2005中构建Qt项目