MinGW Makefile project in QtCreator



  • I would like to edit code and build an existing Makefile project with QtCreator (I downloaded the MinGW version of Qt).
    The project I'm going to work with already has a Makefile and it compiles fine with MinGW (MSYS2) launching 'make' from a specific folder.
    As an example, but it could be any other one, please take a look to this repository:

    https://github.com/bluekitchen/btstack

    the desired Makefile is found at the following path: /port/windows-winusb/Makefile
    I created a new "Import Existing Project" in QtCreator. In the Projects / Build window I selected the folder above as "build directory". Now when I try to either make or clean the project the compiler complains about the "CORE" and "COMMON" macro. Removing them complains about a invalid invocation for include ${BTSTACK_ROOT}/example/Makefile.inc, etc...

    Does the MinGW compiler shipped along with Qt is different than the one that comes with MSYS2?



  • @Mark81 The problem was the first value in the PATH variable that led to use another compiler. I think QtCreator should not rely on that variable to invoke the compiler selected in the Tools > Kit window


  • Lifetime Qt Champion

    Hi,

    In that case, where should Qt Creator look for when starting the compiler ?


  • Moderators

    Hi @Mark81,

    By default, Qt Creator uses your global system environment (including your global PATH) when compiling. There is no way to tell it to ignore a particular item in the PATH.

    If you want Qt Creator to avoid using a particular toolchain, then the best thing to do is to remove it from the global PATH. In general, if you want to use multiple versions of a toolchain on your machine, it is best not to put any of them in the global PATH.


    After you remove MSYS2 from your PATH, if you want to use it outside of Qt Creator, you can temporarily add it to the non-global environment before compiling.

    For example, add this to a batch file called setenvironment.bat: path = %path%;C:\MSYS2\MinGW\bin\ (replace "C:\MSYS2\MinGW" with your actual folder). Then, run the batch file before you compile:

    D:\MyProject\src> setenvironment.bat
    D:\MyProject\src> make
    D:\MyProject\src> make install
    

    Alternatively, you can tell Qt Creator to ignore the system environment.

    Open your project in Qt Creator, and open Projects Mode (Ctrl + 5). Under "Build Environment", check "Clear system environment". Note, you will need to do this for every kit in every project.



  • @SGaist said in MinGW Makefile project in QtCreator:

    In that case, where should Qt Creator look for when starting the compiler ?

    In the folder where the compiler is placed, of course :)
    Tools > options > build&run > compilers: here there are the full (absolute) paths.



  • @JKSH said in MinGW Makefile project in QtCreator:

    By default, Qt Creator uses your global system environment (including your global PATH) when compiling. There is no way to tell it to ignore a particular item in the PATH.

    Thanks for the clarification.
    As said to SGaist, I don't understand why it cannot use the compiler's path instead of rely on env vars...


  • Moderators

    @Mark81 said in MinGW Makefile project in QtCreator:

    Thanks for the clarification.
    As said to SGaist, I don't understand why it cannot use the compiler's path instead of rely on env vars...

    You're welcome.

    Qt Creator does not call the compiler directly. It simply calls mingw32-make.exe and tells it which Makefile to use.

    mingw32-make.exe is the one that calls the compiler (g++.exe). The Makefile does not contain the absolute path to the compiler, so it searches your system environment to find g++.exe.



  • @JKSH said in MinGW Makefile project in QtCreator:

    Qt Creator does not call the compiler directly. It simply calls mingw32-make.exe and tells it which Makefile to use.

    mingw32-make.exe is the one that calls the compiler (g++.exe). The Makefile does not contain the absolute path to the compiler, so it searches your system environment to find g++.exe.

    Ah ok, it makes sense.
    So far, the only way might be QtCreator should add to the sys env of the shell the path of the selected compiler. But perhaps they rely on the knowledge of the users :)


Log in to reply