Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. setting up precompiled header
Forum Updated to NodeBB v4.3 + New Features

setting up precompiled header

Scheduled Pinned Locked Moved Qt Creator and other tools
qtcreatormsvcpch
3 Posts 2 Posters 2.1k Views 2 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.
  • A Offline
    A Offline
    amigo421
    wrote on 12 Mar 2015, 15:29 last edited by
    #1

    Hi

    please clarify me with precompiled headers for latest Qtc and msvc2013 toolchain.
    my understanding this from Visual Studio is:

    1. set option use precompiled headers for a project and specify .h file for this
    2. mark .cpp stub file to generate pch (usually this is stdafx.cpp) - create pch option on this file
    3. set : use pch on all other cpp files in the project.
      Typically we do not do all the steps manually , VS does this itself at project generating time

    in Qtc , I see a few options in the documentation and a few opinions in a forums:

    1. use
      PRECOMPILED_HEADER = project_pch.h
      or directly
      CONFIG += project_pch.h
      do I understand this line from doc correct?
      "CONFIG += precompile_header"
      "precompile_header" here seems not a file name but a file definition?
    2. undocumented option PRECOMPILED_HEADER - what is it? is it required? looks like an option to specify "create PCH" file in MSVC
      PRECOMPILED_HEADER = $${SOURCECODE_DIR}/precompiled_header.h
      win32-msvc* {
      PRECOMPILED_SOURCE = $${SOURCECODE_DIR}/precompiled_header.cpp
      }
      why all sources use win32-msvc* {... ???
      does this work for msvc only? and does not for mingw???

    So please clarify the questions or just explain right way which is really working

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on 12 Mar 2015, 16:08 last edited by
      #2

      Assuming your precompiled header file is called stdafx.h all you need to do for MSVC is include it in your .cpp files and add this to the .pro:

      PRECOMPILED_HEADER = stdafx.h
      

      You don't need the stdafx.cpp file. You don't need it in Visual Studio either as you can set create on any of your cpp files.
      PRECOMPILED_HEADER is not undocumented. It's described in the qmake variables documentation.
      The undocumented one is PRECOMPILED_SOURCE. This is an equivalent of explicitly marking a cpp file that builds the precompiled header (e.g. stdafx.cpp). But, as stated above, you don't usually need it.

      As stated in this doc PRECOMPILED_HEADER is supported only on selected platforms, including MSVC. If you're planning to port to some unsupported platform surround it with win32-msvc* { ... } like in your example to disable it on all other compilers.
      It says it works on Unix gcc, and so by extension it also works with MinGW (which is Windows port of gcc).

      I'm using it with both MSVC and MinGW and it works fine.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        amigo421
        wrote on 12 Mar 2015, 19:51 last edited by
        #3

        thank you !

        you are right, that was typo: PRECOMPILED_HEADER
        I've mean PRECOMPILED_SOURCE of course.

        that sounds oddly for me that stdafx.cpp is not required,
        but ok, I'll try to build

        thanks again!

        1 Reply Last reply
        0

        1/3

        12 Mar 2015, 15:29

        • Login

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