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

Is possible to change that qmake uses by default /usr/bin/gcc?



  • I have added my new compiler with the path gcc-11 & g++-11, and actually create a new kit that uses by default that compiler:
    image
    but when i recompile my projects i get:

    :-1: warning: "/usr/bin/g++" is used by qmake, but "/usr/bin/g++-11" is configured in the kit.
    Please update your kit (New kit with new compiler) or choose a mkspec for qmake that matches your target environment better.
    

    so i read that the solution is to add to the project file:

    QMAKE_CC = gcc-11
    QMAKE_CXX = g++-11
    

    BUT I can't do that. I will be working on a project with other users through git, and all of our projects are going to be developed in linux in gcc 11.2, and we want to compile for windows & mac (with any compiler) actually so i cannot modify the project file in that way.
    So, If possible i would like to create a kit that actually uses my gcc-11, if not possible, I would prefer to configure my qt to always use gcc-11 by default (otherwise i guess I will change my /usr/bin/gcc archive :/)


  • Moderators

    @MyNameIsDan said in Is possible to change that qmake uses by default /usr/bin/gcc?:

    and we want to compile for windows & mac (with any compiler) actually so i cannot modify the project file in that way.

    But you can scope it down to linux only:

    linux {
      QMAKE_CC = gcc-11
      QMAKE_CXX = g++-11
    }
    

    Anyway, looks like the solutions for you are:

    • modify mkspec qt-installation-path/mkspecs/common/g++-base.conf and change all the paths and flags as you like. If you don't want to modify existing mkspecs, you can make your own and then call qmake with -spec path/to/your/specs
    • or replace /usr/bin/g++ with a symlink to `/usr/bin/g++-11'

  • Moderators

    @MyNameIsDan said in Is possible to change that qmake uses by default /usr/bin/gcc?:

    and we want to compile for windows & mac (with any compiler) actually so i cannot modify the project file in that way.

    But you can scope it down to linux only:

    linux {
      QMAKE_CC = gcc-11
      QMAKE_CXX = g++-11
    }
    

    Anyway, looks like the solutions for you are:

    • modify mkspec qt-installation-path/mkspecs/common/g++-base.conf and change all the paths and flags as you like. If you don't want to modify existing mkspecs, you can make your own and then call qmake with -spec path/to/your/specs
    • or replace /usr/bin/g++ with a symlink to `/usr/bin/g++-11'


  • @MyNameIsDan
    Does qmake/.pro file allow use of environment variables? If so could you use that to get your personal desired value in there, and the qmake/.pro have a "default" of what other people need to use if the environment variable is not defined, so just you can set it?



  • @sierdzio actually the first one is a good one, if the project is developed in linux and we accept the fact that is going do be in other compiler for the final release for other platforms, that is viable.
    But right now I prefer to modify my mkspecs.



  • There are two ways I see to make you opt in to these settings explicitly, so that it is specific to your machine (another Linux machine might be configured differently):

    1. Use an additional config variable which you specify when compiling on your machine. Inside the .pro file:
    LINUX_GCC11_WORKAROUND {
      QMAKE_CC = gcc-11
      QMAKE_CXX = g++-11
    }
    

    Inside QtCreator in the projects settings for the qmake step specify CONFIG+=LINUX_GCC11_WORKAROUND as additional argument. On the command line just add it to your options: qmake CONFIG+=LINUX_GCC11_WORKAROUND [...] MyProject.pro This is quite similar to @sierdzio's suggestion. But it is more explicit if other Linux machines are configured differently.

    1. My preferred method for this is a user-specific config.pri. This is what we have in our .pro files:
    exists(config.pri): include(config.pri)
    

    Every user can specify whatever they like inside the config.pri. This file will not be checked in to version control so that everyone can keep their own settings. Nobody ever has to know about your machine specific settings. If there are a dozen workarounds for different machines your .pro file will not be cluttered up by all the different workarounds like in version 1. I described.

    The two approaches can also be combined: If you want to keep track of all workarounds (maybe put them in a workarounds.pri checked into the version control) you can add CONFIG+=LINUX_GCC11_WORKAROUND into your config.pri to enable them on your machine only.


Log in to reply