Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. Compiling on MacOs with a Makefile
Forum Updated to NodeBB v4.3 + New Features

Compiling on MacOs with a Makefile

Scheduled Pinned Locked Moved Solved Installation and Deployment
3 Posts 2 Posters 1.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    keeely
    wrote on last edited by
    #1

    I've installed Qt on MacOs Ventura via Homebrew with:

    brew install qt
    

    Which seems to have given me a bunch of headers and other stuff I'd expect to be able to compile programs with. So I created a 'hello world' program of sorts:

    #include <QApplication>
    #include <QLabel>
    
    int main(int argc, char *argv[])
    {
        QApplication app(argc, argv); 
        QLabel *label = new QLabel("Hello, World!"); 
        label->show(); 
        return app.exec(); 
    }
    

    And an accompanying Makefile:

    PREFIX = /usr/local/opt/qt@5
    
    INCLUDE = -I$(PREFIX)/include \
    	-I$(PREFIX)/include/QtCore \
    	-I$(PREFIX)/include/QtWidgets \
    	-I$(PREFIX)/include/QtGui
    
    LIB = -L$(PREFIX)/lib
    
    main: main.cpp
    	g++ -fPIC -std=c++17 $(INCLUDE) $(LIB) -lQtCore -lQtGui -lQtWidgets $< -o $@
    

    The program compiles but when linking doesn't find QtCore. Which isn't surprising, because there is no QtCore.dylib either in the lib directory I've specified or in any of the files the brew command installed. There is also no QtCore.a or QtCore.so. I wondered if this was just a mistake on the part of the Homebrew maintainers, however I also tried the same thing with Qt5:

    brew install qt@5
    

    I changed my include and library paths to match but the same thing happened. So my question is, where are the actual libraries? Should I be creating an issue on the Homebrew page, or am I missing something fundamental here?

    SGaistS 1 Reply Last reply
    0
    • K keeely

      I've installed Qt on MacOs Ventura via Homebrew with:

      brew install qt
      

      Which seems to have given me a bunch of headers and other stuff I'd expect to be able to compile programs with. So I created a 'hello world' program of sorts:

      #include <QApplication>
      #include <QLabel>
      
      int main(int argc, char *argv[])
      {
          QApplication app(argc, argv); 
          QLabel *label = new QLabel("Hello, World!"); 
          label->show(); 
          return app.exec(); 
      }
      

      And an accompanying Makefile:

      PREFIX = /usr/local/opt/qt@5
      
      INCLUDE = -I$(PREFIX)/include \
      	-I$(PREFIX)/include/QtCore \
      	-I$(PREFIX)/include/QtWidgets \
      	-I$(PREFIX)/include/QtGui
      
      LIB = -L$(PREFIX)/lib
      
      main: main.cpp
      	g++ -fPIC -std=c++17 $(INCLUDE) $(LIB) -lQtCore -lQtGui -lQtWidgets $< -o $@
      

      The program compiles but when linking doesn't find QtCore. Which isn't surprising, because there is no QtCore.dylib either in the lib directory I've specified or in any of the files the brew command installed. There is also no QtCore.a or QtCore.so. I wondered if this was just a mistake on the part of the Homebrew maintainers, however I also tried the same thing with Qt5:

      brew install qt@5
      

      I changed my include and library paths to match but the same thing happened. So my question is, where are the actual libraries? Should I be creating an issue on the Homebrew page, or am I missing something fundamental here?

      SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by SGaist
      #2

      Hi and welcome to devnet,

      You're on macOS not Linux/Unix.

      Libraries end in .dylib but most important many of them including Qt are provided in the form of frameworks. To use them you have make use of -F and -framework in place of -L and -l.

      That said, I would recommend using a project manager such as CMake or even qmake but it has been deprecated in Qt 6.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      K 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi and welcome to devnet,

        You're on macOS not Linux/Unix.

        Libraries end in .dylib but most important many of them including Qt are provided in the form of frameworks. To use them you have make use of -F and -framework in place of -L and -l.

        That said, I would recommend using a project manager such as CMake or even qmake but it has been deprecated in Qt 6.

        K Offline
        K Offline
        keeely
        wrote on last edited by
        #3

        @SGaist
        Thank you for getting back to me. Once I googled what a framework was it was all relatively simple to converge on a solution. For anyone else wanting the same thing, this Makefile does the trick:

        PREFIX = /usr/local/opt/qt
        
        INCLUDE = -I$(PREFIX)/include   \
        	-I$(PREFIX)/include/QtCore \
        	-I$(PREFIX)/include/QtWidgets \
        	-I$(PREFIX)/include/QtGui
        
        LIB = -F$(PREFIX)/Frameworks
        
        main: main.cpp
        	g++ -fPIC -std=c++17 $(INCLUDE) $(LIB) -framework QtCore -framework QtGui -framework QtWidgets $< -o $@
        	
        
        1 Reply Last reply
        1
        • K keeely has marked this topic as solved on

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved