Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Building for Linux and Windows
Forum Updated to NodeBB v4.3 + New Features

Building for Linux and Windows

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 5 Posters 469 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.
  • deisikD Offline
    deisikD Offline
    deisik
    wrote on last edited by deisik
    #1

    I am porting my application to Windows and I want to use the same source code directory for building on both Linux and Windows so as not to end up having to support two different projects

    Will setting up two different build directories for each platform do the trick, with the same source code edited and compiled on Linux for Linux and on Windows for Windows?

    Will this setup work and if not, which is the "right" way of achieving this?

    Christian EhrlicherC JoeCFDJ S 3 Replies Last reply
    0
    • deisikD deisik

      I am porting my application to Windows and I want to use the same source code directory for building on both Linux and Windows so as not to end up having to support two different projects

      Will setting up two different build directories for each platform do the trick, with the same source code edited and compiled on Linux for Linux and on Windows for Windows?

      Will this setup work and if not, which is the "right" way of achieving this?

      Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @deisik said in Building for Linux and Windows:

      Will this setup work and if not, which is the "right" way of achieving this?

      Use a proper source code management system like git and share your repository via e.g. github.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      JoeCFDJ 1 Reply Last reply
      3
      • Christian EhrlicherC Christian Ehrlicher

        @deisik said in Building for Linux and Windows:

        Will this setup work and if not, which is the "right" way of achieving this?

        Use a proper source code management system like git and share your repository via e.g. github.

        JoeCFDJ Offline
        JoeCFDJ Offline
        JoeCFD
        wrote on last edited by
        #3

        @Christian-Ehrlicher companies will use a server for its products instead of github.

        1 Reply Last reply
        0
        • deisikD deisik

          I am porting my application to Windows and I want to use the same source code directory for building on both Linux and Windows so as not to end up having to support two different projects

          Will setting up two different build directories for each platform do the trick, with the same source code edited and compiled on Linux for Linux and on Windows for Windows?

          Will this setup work and if not, which is the "right" way of achieving this?

          JoeCFDJ Offline
          JoeCFDJ Offline
          JoeCFD
          wrote on last edited by JoeCFD
          #4

          @deisik which qt version are you using now?
          if you use qt5, either pro file or cmake will do the job for you. In pro file you can use

          unix {
              do settings for linux
          }
          
          win32 {
              do settings for Windows
          }
          

          cmake file has similar settings.

          if you use qt6, cmake is preferred. It depends on how big your project is. If it is small, one cmake or pro file is good enough. if your project is big, you can split the build file into a few files. For example, I build my project for Linux and Android with about 8-10 build files for easier changes.

          since your build your project on two platforms, you sure need two dirs. But you use the same dir name.

          deisikD 1 Reply Last reply
          0
          • JoeCFDJ JoeCFD

            @deisik which qt version are you using now?
            if you use qt5, either pro file or cmake will do the job for you. In pro file you can use

            unix {
                do settings for linux
            }
            
            win32 {
                do settings for Windows
            }
            

            cmake file has similar settings.

            if you use qt6, cmake is preferred. It depends on how big your project is. If it is small, one cmake or pro file is good enough. if your project is big, you can split the build file into a few files. For example, I build my project for Linux and Android with about 8-10 build files for easier changes.

            since your build your project on two platforms, you sure need two dirs. But you use the same dir name.

            deisikD Offline
            deisikD Offline
            deisik
            wrote on last edited by deisik
            #5

            @JoeCFD Only a small part of my app needs special love (the Windows-only part that calls some external dlls), and I use stubs where the code should be separated between the platforms

            It is too early to tell, but it looks like my setup is working. For a one-man army and as long as you don't try to edit the same file from Linux and Windows simultaneously, you should do fine

            @JoeCFD said in Building for Linux and Windows:

            since your build your project on two platforms, you sure need two dirs. But you use the same dir name.

            I use the same source directory and two separate build directories for each platform (like project-build-Linux and project-build-Windows) in the same parent directory on the Linux machine as this is what shadow build requires as far as I can tell

            1 Reply Last reply
            0
            • deisikD deisik

              I am porting my application to Windows and I want to use the same source code directory for building on both Linux and Windows so as not to end up having to support two different projects

              Will setting up two different build directories for each platform do the trick, with the same source code edited and compiled on Linux for Linux and on Windows for Windows?

              Will this setup work and if not, which is the "right" way of achieving this?

              S Offline
              S Offline
              SimonSchroeder
              wrote on last edited by
              #6

              @deisik said in Building for Linux and Windows:

              Will setting up two different build directories for each platform do the trick, with the same source code edited and compiled on Linux for Linux and on Windows for Windows?

              Yes, this will do. You should make sure to just have a single project file both for Windows and Linux. Compiling to different directories is mostly sufficient. (Now, that I think about this: I believe that Qt Creator for qmake projects will write a Makefile to the main folder both on Windows and Linux. This might mess up a few things when you switch. Toggling between Debug and Release mode in Qt Creator should recreate the Makefile in this case. Better: Use CMake instead as its makefiles are stored in the build directory.)

              To me, your approach is a valid solution to the problem.

              deisikD andrA 2 Replies Last reply
              1
              • S SimonSchroeder

                @deisik said in Building for Linux and Windows:

                Will setting up two different build directories for each platform do the trick, with the same source code edited and compiled on Linux for Linux and on Windows for Windows?

                Yes, this will do. You should make sure to just have a single project file both for Windows and Linux. Compiling to different directories is mostly sufficient. (Now, that I think about this: I believe that Qt Creator for qmake projects will write a Makefile to the main folder both on Windows and Linux. This might mess up a few things when you switch. Toggling between Debug and Release mode in Qt Creator should recreate the Makefile in this case. Better: Use CMake instead as its makefiles are stored in the build directory.)

                To me, your approach is a valid solution to the problem.

                deisikD Offline
                deisikD Offline
                deisik
                wrote on last edited by deisik
                #7

                After testing my setup for nearly two months, I should say that it works in general, with the caveat being that the compile times on Windows are notably longer (apparently due to network as the project resides on the Linux machine and, consequently, its build directory is there too)

                1 Reply Last reply
                0
                • S SimonSchroeder

                  @deisik said in Building for Linux and Windows:

                  Will setting up two different build directories for each platform do the trick, with the same source code edited and compiled on Linux for Linux and on Windows for Windows?

                  Yes, this will do. You should make sure to just have a single project file both for Windows and Linux. Compiling to different directories is mostly sufficient. (Now, that I think about this: I believe that Qt Creator for qmake projects will write a Makefile to the main folder both on Windows and Linux. This might mess up a few things when you switch. Toggling between Debug and Release mode in Qt Creator should recreate the Makefile in this case. Better: Use CMake instead as its makefiles are stored in the build directory.)

                  To me, your approach is a valid solution to the problem.

                  andrA Offline
                  andrA Offline
                  andr
                  wrote on last edited by
                  #8

                  @SimonSchroeder said in Building for Linux and Windows:

                  Qt Creator for qmake projects will write a Makefile to the main folder both on Windows and Linux

                  There is no difference between qmake and cmake here.

                  It will put the Makefile in you build directory, so if you have different build dirs for the Linux and Windows builds that just works.

                  1 Reply Last reply
                  0

                  • Login

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