sflee sflee - 1 month ago 14
C++ Question

How to build Qt project in linux with cmake

I am using ubuntu 14.04, cmake 2.8.12.2, Qt5.6.2 (a built version), GNU make 3.81




After I run cmake with

cmake PathToSource -G "Eclipse CDT4 - Unix Makefiles"


I do
make
. I get
#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. "\




I then download source file of
Qt5.7.0
, build and install it without problem. I do again
cmake PathToSource -G "Eclipse CDT4 - Unix Makefiles"
, make it. I get many errors, such as
/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);
and
/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); }




How to solve it?

Answer

Qt 5.7 requires C++11 compiler. If you get that kind of error from auto pair, it sounds like your compiler is not compiling C++11 code. There are two possible reasons:

  1. You just need to pass -std=c++11 to your compiler, as explaned under this question.

  2. You have too old compiler. However, since you compiled Qt 5.7 itself with the same compiler, this shouldn't be the problem for you.

Comments