Search code examples
c++qtenvironment-variablesqt-creatorqmake

Can you use environmental variables in qt creator?


So I use a bunch of libraries in the code I'm currently working in. Right now I include them by doing things like win32:LIBS += "C:/my/location/Tools/libcurl/trunk/lib/Debug/curllib.lib". However, I have an environmental variable that defined %TOOLS% as C:/my/location/Tools/. I tried to simply change my include to win32:LIBS += "%TOOLS%libcurl/trunk/lib/Debug/curllib.lib", but it could not find the files. I looked online and this should be doable. Am I missing something simple, like a way to tell Qt creator to look at window's environmental variables?

Thanks!


Solution

  • To get the content of an environment variable when qmake is processed, you can use the following :

    win32:LIBS += $$(TOOLS)/libcurl/trunk/lib/Debug/curllib.lib
    

    TOOLS should be an environment variable set to C:/my/location/Tools.

    But you don't necessarily need an environment variable for this. You can simple define a variable in your .pro file :

    TOOLS="C:/my/location/Tools"
    

    And use it's value by prefixing it with $$ :

    win32:LIBS += $$TOOLS/libcurl/trunk/lib/Debug/curllib.lib