QT5 Compilation - catastrophic error



  • A similar question was asked in the post "Qt5 Compilation - global.h" , with a twist. I believe that I am not using
    -reduce-relocations.

    I have compiled qt5 using the steps from " Building qt5 with git". I am using Debian Linux with gcc , cmake-2.8.11.
    The steps I followed are shown below. There are no errors when compiling or installing. But I get the following message when I try to compile within Creator. I get the same error with Creator 2.7 and 2.8. As a test I am using example problems that are installed with Qt5. Is -reduce-relocations being built even though I am not specifying it in the build process?

    Build steps
    git clone git://gitorious.org/qt/qt5.git qt5
    cd qt5
    perl init-repository --no-webkit
    ./configure -prefix /opt/local/Qt-5.1.1 -developer-build -opensource -nomake tests
    make
    make install

    ERROR MESSAGE
    /opt/local/qt/Qt-5.1.1/include/QtCore/qglobal.h:975: catastrophic error: #error directive: "You must build your code with position independent code if Qt was built with -reduce-relocations. " "Compile your code with -fPIC or -fPIE."

    error "You must build your code with position independent code if Qt was built with -reduce-relocations. "\


  • Moderators

    When you run configure, the script prints out all the options and settings it is using. Could be good to read that list (just pipe it to a file or grep for relocations).

    Otherwise, you can indeed try building with -fPIC or PIE :) You can add compile flags in Qt Creator's project options, or in .pro file (I don't know about cmake, but they must have an option for that, too).



  • If you are using CMake: SET (CMAKE_CXX_FLAGS "-fPIC")

    I put this line in the root CMakeList.txt file of my project.

    This problem does remind me of something. Yet, all examples compile just fine without the use of additional options with qmake...



  • I had this error after I removed Qt5Widgets_INCLUDE_DIRS from the list of include_directories.
    But widgets were not link to target!.

    @find_package(Qt5Core REQUIRED)
    find_package(Qt5Widgets REQUIRED)
    find_package(Qt5Sql REQUIRED)
    find_package(Qt5Test REQUIRED)

    include_directories(
    ${Qt5Core_INCLUDE_DIRS}
    #${Qt5Widgets_INCLUDE_DIRS} # After I comment this line out, the error happens.
    ${Qt5Sql_INCLUDE_DIRS}
    ${Qt5Test_INCLUDE_DIRS}
    )

    add_executable(${TARGET_NAME} $<TARGET_OBJECTS:objlib${TARGET_NAME}> main.cpp)
    qt5_use_modules(${TARGET_NAME} Sql) @



  • [quote author="Guigui" date="1371494219"]If you are using CMake: SET (CMAKE_CXX_FLAGS "-fPIC")

    I put this line in the root CMakeList.txt file of my project.

    This problem does remind me of something. Yet, all examples compile just fine without the use of additional options with qmake...[/quote]

    With this line in Your CMakeLists.txt you make your project compatible only with gnu compilers, which is not nice ;)

    EDIT:
    right way of doing it:
    SET (CMAKE_POSITION_INDEPENDENT_CODE ON)

    "here is and example":https://github.com/Cockatrice/Cockatrice/commit/9cfb09cd5b25a01fb142d425ba70b77b89f65a09



  • [quote author="Guigui" date="1371494219"]If you are using CMake: SET (CMAKE_CXX_FLAGS "-fPIC")

    I put this line in the root CMakeList.txt file of my project.

    This problem does remind me of something. Yet, all examples compile just fine without the use of additional options with qmake...[/quote]

    With this line in Your CMakeLists.txt you make your project compatible only with gnu compilers, which is not nice ;)

    EDIT:
    right way of doing it:
    SET (CMAKE_POSITION_INDEPENDENT_CODE ON)

    "here is and example":https://github.com/Cockatrice/Cockatrice/commit/9cfb09cd5b25a01fb142d425ba70b77b89f65a09


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.