Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Problem with-fPiC and -fPIE (CMake + conan)



  • Hello!
    I have a problem with compile when I am linking Qt5::Core.
    Please help. Logs below.

    Ubuntu Linux x86_64, GCC 8.3, cmake 3.20.5, conan 1.38.0

    conanfile:

    [requires]
    bitsery/5.1.0 
    boost/1.76.0
    cereal/1.3.0
    cppzmq/4.6.0
    fmt/6.2.0
    poco/1.9.4
    qt/5.15.2
    yaml-cpp/0.6.3
    sqlite3/3.31.1
    openssl/1.1.1k
    pcre/8.44
    expat/2.2.9
    
    [options]
    *:shared=True
    *:fPIC=True
    *:python=True
    *:without_python=False
    yaml-cpp:shared=False
    zlib:shared=False
    Qt:qtsvg=True
    Qt:qtcharts=True
    Qt:qtwinextras=True
    
    [generators]
    cmake_find_package
    cmake_paths
    
    [imports]
    bin, *.dll -> ./bin
    lib, *.dll -> ./bin
    

    CMakeLists.txt;

    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
    
    set_target_properties(Qt5::Core PROPERTIES MAP_IMPORTED_CONFIG_COVERAGE "RELEASE")
    
    add_executable(bootstrap src/main.cpp)
    
    #set(CMAKE_POSITION_INDEPENDENT_CODE ON)
    
    target_link_libraries(bootstrap PRIVATE model model_python_api Qt5::Core)
    

    build log:

    root@472d843da9df:/usr/src/ecp/build# ninja
    [5/13] Building CXX object Model/utils/bootstrap/CMakeFiles/bootstrap.dir/src/main.cpp.o
    FAILED: Model/utils/bootstrap/CMakeFiles/bootstrap.dir/src/main.cpp.o 
    /usr/bin/c++ -DBOOST_ALL_DYN_LINK -DBOOST_STACKTRACE_ADDR2LINE_LOCATION=\"/usr/bin/addr2line\" -DBOOST_STACKTRACE_USE_ADDR2LINE -DBOOST_STACKTRACE_USE_BACKTRACE -DBOOST_STACKTRACE_USE_NOOP -DENABLE_QT_SUPPORT -DFMT_SHARED -DPOCO_UNBUNDLED -DQT_CORE_LIB -I../Model/include -isystem /root/.conan/data/poco/1.9.4/_/_/package/d23a2b97fdf1fc6d3919807d989057c52bddb25b/include -isystem /root/.conan/data/pcre/8.44/_/_/package/ccf96cec28b048ff98fa1cdb8b74e29e8d61b4cd/include -isystem /root/.conan/data/bzip2/1.0.8/_/_/package/2f9654b689b6e33c35309bd924ec8e60c3e1a4a1/include -isystem /root/.conan/data/zlib/1.2.11/_/_/package/761432f3453a17c960259b5b2605153e3bcffd7d/include -isystem /root/.conan/data/expat/2.2.9/_/_/package/44b0613cc04134934203f96ecc4bc2e4eb170ab0/include -isystem /root/.conan/data/sqlite3/3.31.1/_/_/package/0f9d8d84ee12e51182129966926a3423b421b98d/include -isystem /root/.conan/data/openssl/1.1.1k/_/_/package/84f3bb983f93794f41c9b7cf49b33e0a5bc42de9/include -isystem /root/.conan/data/cereal/1.3.0/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include -isystem /root/.conan/data/fmt/6.2.0/_/_/package/9ff4b7ca1cb37c0de837519f7aeff8bf47ddd212/include -isystem /root/.conan/data/yaml-cpp/0.6.3/_/_/package/038f8796e196b3dba76fcc5fd4ef5d3d9c6866ec/include -isystem /root/.conan/data/boost/1.76.0/_/_/package/3a3c36d035b5405a22fef2d42d8ff501743e55b9/include -isystem /root/.conan/data/libbacktrace/cci.20210118/_/_/package/84f3bb983f93794f41c9b7cf49b33e0a5bc42de9/include -isystem /root/.conan/data/qt/5.15.2/_/_/package/3236f93fbdd400eb2f4d3617544a08fae402b2f9/include -isystem /root/.conan/data/qt/5.15.2/_/_/package/3236f93fbdd400eb2f4d3617544a08fae402b2f9/include/QtCore -isystem /root/.conan/data/pcre2/10.37/_/_/package/59ad7c1a5357815a7cb5b96ec3667f89ad5a9e4e/include -isystem /root/.conan/data/double-conversion/3.1.5/_/_/package/9ff4b7ca1cb37c0de837519f7aeff8bf47ddd212/include -isystem /root/.conan/data/icu/69.1/_/_/package/7219cd33fc5b4a7063658015df557ac9fc65bf63/include -isystem /root/.conan/data/zstd/1.5.0/_/_/package/84f3bb983f93794f41c9b7cf49b33e0a5bc42de9/include -fPIC -g -fPIE -MD -MT Model/utils/bootstrap/CMakeFiles/bootstrap.dir/src/main.cpp.o -MF Model/utils/bootstrap/CMakeFiles/bootstrap.dir/src/main.cpp.o.d -o Model/utils/bootstrap/CMakeFiles/bootstrap.dir/src/main.cpp.o -c ../Model/utils/bootstrap/src/main.cpp
    In file included from /root/.conan/data/qt/5.15.2/_/_/package/3236f93fbdd400eb2f4d3617544a08fae402b2f9/include/QtCore/qcoreapplication.h:43,
                     from /root/.conan/data/qt/5.15.2/_/_/package/3236f93fbdd400eb2f4d3617544a08fae402b2f9/include/QtCore/QCoreApplication:1,
                     from ../Model/utils/bootstrap/src/main.cpp:18:
    /root/.conan/data/qt/5.15.2/_/_/package/3236f93fbdd400eb2f4d3617544a08fae402b2f9/include/QtCore/qglobal.h:1286:4: error: #error "You must build your code with position independent code if Qt was built with -reduce-relocations. " "Compile your code with -fPIC (and not with -fPIE)."
     #  error "You must build your code with position independent code if Qt was built with -reduce-relocations. "\
        ^~~~~
    [9/13] Building CXX object Model/python/CMakeFiles/model_python_api.dir/PythonModel.cpp.o
    In file included from /root/.conan/data/boost/1.76.0/_/_/package/3a3c36d035b5405a22fef2d42d                 from /root/.conan/data/boost/1.76.0/_/_/package/3a3c36d035b5405a22fef2d42d8ff501743e55b9/include/boost/python/suite/indexing/indexing_suite.hpp:14,
                     from /root/.conan/data/boost/1.76.0/_/_/package/3a3c36d035b5405a22fef2d42d8ff501743e55b9/include/boost/python/suite/indexing/map_indexing_suite.hpp:9,
                     from ../Model/python/PythonModel.cpp:19:
    /root/.conan/data/boost/1.76.0/_/_/package/3a3c36d035b5405a22fef2d42d8ff501743e55b9/include/boost/bind.hpp:41:1: note: #pragma message: The practice of declaring the Bind placeholders (_1, _2, ...) in the global namespace is deprecated. Please use <boost/bind/bind.hpp> + using namespace boost::placeholders, or define BOOST_BIND_GLOBAL_PLACEHOLDERS to retain the current behavior.
     )
     ^
    ninja: build stopped: subcommand failed8ff501743e55b9/include/boost/python/iterator.hpp:25,
    

Log in to reply