1

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?

sflee
  • 1,659
  • 5
  • 32
  • 63

1 Answers1

2

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.

Community
  • 1
  • 1
hyde
  • 60,639
  • 21
  • 115
  • 176
  • I build `Qt5.7.0`, with `g++4.8.4`, then I add `-std=c++11`. No more `error: ‘pair’ does not name a type` appear, but then 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. "\` again. /.\ – sflee Oct 29 '16 at 06:10
  • 1
    Well, just add `-fPIC` to your project compiler flags, same way you added `-std=c++11`? – hyde Oct 29 '16 at 06:16
  • 3
    You can also let CMake manage the std flag by itself by using `set(CMAKE_CXX_STANDARD 11)`. – cmourglia Oct 29 '16 at 09:43