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

Using G++ instead of clang on macOS catalina



  • I'm in the proces of getting a program (theli) to compile on macOS catalina. The reason this is an issue related to Qt is that this program insists on using openmpi, in particular, it passes the -openmp flag to the C++ compiler and the linker.

    Now, clang on Catalina does not support -openmp at all (tried it, got complaints about -openmp from the standard clang that is used by Qt on macOS). But it should compile with G++, and in fact it does from the command line using some generated makefile.

    The compiled binary still crashes for one reason or another, so the reasonable thing then to do is start the Qt IDE (the program is written in Qt) and sets breakpoints.

    This is where it goes wrong. There is no default GNU compiler anymore in Qt for macOS, I can only choose clang, which does not like -openmp anymore. So I try to add a GCC kit. This does not really work either. I have a home-brew-installed GCC, but when I choose that the compiler kit box insists on resolving the soft links home-brew puts in/usr/local/bin. That's beside the point of having home-brew, but if it works, that's fine.

    But it doesn't work. I get this error
    "project ERROR: failed to parse default search paths from compiler output". There are no search paths to enter in the compiler definition that I can see. Googling tells me about a folder mkspec, but the contents of it don't make it obvious why the Qt IDE only shows clang.

    So I'm stuck.

    Qt Creator is 5.9.6, as the program's author appears to be using that. I am having enough differences as it is so I am not going on an adventure of trying even more things that will most likely not work. Newer qt versions because of better Catalina support are fine.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    From the top of my head, you will likely have to create your own mkspec to use GCC. Also, be aware that there is no official support for non Apple compilers.

    That said, before trying to build theli, did you try do build a dummy OpenMPI application using the Qt infrastructure ?



  • No, I have not. the openmp aspect of theli is not the reason I am interested in trying to get it to compile.

    Regarding the mkspec creation, how would this work in detail? There is something there, a file called macx-g++, that looks to me the mkspec I would need to create in the first place. But it is not used, at least not in the IDE, AFAICS. I can't see how my totally uninformed attempt would fare better.


  • Lifetime Qt Champion

    Even if it's not your main point of interest, the dummy application I s mainly to ensure that you can use your version if OpenMPI with clang.

    You can tell the mkspec to use to qmake. Note that the gcc one is essentially there for historical reasons.



  • @SGaist the program has a truckload of dependencies, all of which could be the source of the crash.

    Anyway, I don't see how specifying a mkspecs file helps me in the IDE. qmake is used to create a Makefile. But the Makefile is not the problem. I changed compilers in the makefile (the recommended hack by the program's author) and that works for compiling. What I want is to have GCC be the default compiler for the IDE, and I don't see how that is going to work. Not that I now much about Qt on Mac.



  • There appears to be a way to use -fopenmp on Apple's clang: add -Xpreprocessor in front of it, both in the compiler and the linker flags. also add -lopm to LIBS.


Log in to reply