如何使用cmake在linux中构建Qt项目

时间:2016-10-29 05:10:32

标签: c++ linux qt

我使用的是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); }
怎么解决?

1 个答案:

答案 0 :(得分:2)

Qt 5.7需要C ++ 11编译器。如果从auto pair得到那种错误,听起来你的编译器没有编译C ++ 11代码。有两个可能的原因:

  1. 您只需将-std=c++11传递给编译器,如under this question所述。

  2. 你的编译器太旧了。但是,由于您使用相同的编译器编译了Qt 5.7本身,这对您来说应该不是问题。