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

qmake escapes spaces within environment variables



  • I have a linux environment variable defined as:

    export GMT_LIBS='-L/bogusDir -lgmt'
    

    I want to access MYLIBS from within my .pro file and add it to the LIBS variable:

    gmtLibs = $$getenv("GMT_LIBS")
    LIBS += $gmtLibs
    

    But when qmake is generating a Makefile, it escapes the space within GMT_LIBS with back-slash, so the Makefile contains:

    LIBS          = $(SUBLIBS) -L/bogusDir\ -lgmt
    

    When ‘make’ processes this Makefile, it does not link with library -lgmt, so results in “undefined reference” errors. If I manually edit the Makefile and remove the ‘\’ preceding -lgmt, then rerun ‘make’, it links properly.

    I get the same escaped space in the Makefile if the .pro file accesses environment variable with this instead of getenv():

    LIBS += $$(GMT_LIBS)
    

    So how do I convince qmake not to escape spaces within environment variables?

    Thanks!


  • Lifetime Qt Champion

    Since these are two parameters but you treat it as one I would go with split()


  • Lifetime Qt Champion

    Since these are two parameters but you treat it as one I would go with split()



  • @Christian-Ehrlicher - that works!

    LIBS += $$split(gmtLibs, " ")
    

    Thanks!


Log in to reply