Extending the INCLUDEPATH and LIBS dirs globally in QtCreator



  • Hello everyone!
    I'm trying to add custom include directories to ones defined in QtCreator(3.3.0) by default. I tried setting environment variables in ~/.bashrc file:

    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/opt/lib
    export CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:$HOME/opt/include/asyncplusplus
    export LIBRARY_PATH=$LIBRARY_PATH:$HOME/opt/lib

    It works well for gcc itself when used from shell, but QtCreator ignores this. If I define these variables also in the Kit options^1 - build succseeds but syntax highlighting and completition does not work.

    The only way to make QtCreator fully support external libraries I have found so far - is to set LIBS and INCLUDEPATH variables in .project file. Which is not satisfactory for me because these paths are different on different systems and puting .project file under version control becomes a nightmare. An example would be boost: on *nix boost is normally accessible from the default include path, but not on Windows...

    I have found some hints, that I could achieve a desired behaviour by modifing .conf files in Qt/5.4/gcc_64/mkspecs/common, but I don't know how to do it correctly.

    What is the best way to solve this problem?



  • I found a solution myself. Not sure if it's a "right" one:
    create a ~/.qtcreator.conf file containing this:

    QMAKE_INCDIR += $$(HOME)/opt/include
    QMAKE_LIBDIR += $$(HOME)/opt/lib
    

    append this:

    include($$(HOME)/.qtcreator.conf)
    

    to qtcreator_installation/5.4/gcc_64/mkspecs/common/linux.conf



  • I have found a reason, why LD_LIBRARY_PATH, CPLUS_INCLUDE_PATH and LIBRARY_PATH variables were ignored by QtCreator: I use KDE and it does not load the .bashrc in the session, but the bash does. So in KDE when you open Konsole - your environment is populated from .bashrc, but other apps, not launched from console - have different environment. So for me the solution was to create $HOME/.kde/env/user.sh file like this:

    #!/bin/bash
    if [ -f ~/.username.bashrc ]; then
        . ~/.username.bashrc
    fi 
    

    ~/.username.bashrc contains my environment variables.



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