precompiled-headers

Is there a way to use pre-compiled headers in VC++ without requiring stdafx.h?

喜欢而已 提交于 2019-11-27 20:48:47
I've got a bunch of legacy code that I need to write unit tests for. It uses pre-compiled headers everywhere so almost all .cpp files have a dependecy on stdafx.h which is making it difficult to break dependencies in order to write tests. My first instinct is to remove all these stdafx.h files which, for the most part, contain #include directives and place those #includes directly in the source files as needed. This would make it necessary to turn off pre-compiled headers since they are dependent on having a file like stdafx.h to determine where the pre-compiled headers stop. Is there a way to

Why use precompiled headers (C/C++)?

与世无争的帅哥 提交于 2019-11-27 11:19:49
Why use precompiled headers? Reading the responses, I suspect what I've been doing with them is kind of stupid: #pragma once // Defines used for production versions #ifndef PRODUCTION #define eMsg(x) (x) // Show error messages #define eAsciiMsg(x) (x) #else #define eMsg(x) (L"") // Don't show error messages #define eAsciiMsg(x) ("") #endif // PRODUCTION #include "targetver.h" #include "version.h" // Enable "unsafe", but much faster string functions #define _CRT_SECURE_NO_WARNINGS #define _SCL_SECURE_NO_WARNINGS // Standard includes #include <stdio.h> #include <tchar.h> #include <iostream>

Sharing precompiled headers between projects in Visual Studio

时光总嘲笑我的痴心妄想 提交于 2019-11-27 11:19:37
I have a solution with many Visual C++ projects, all using PCH, but some have particular compiler switches turned on for project-specific needs. Most of these projects share the same set of headers in their respective stdafx.h (STL, boost, etc). I'm wondering if it's possible to share PCH between projects, so that instead of compiling every PCH per-project I could maybe have one common PCH that most projects in the solution could just use. It seems possible to specify the location of the PCH as a shared location in the project settings, so I have a hunch this could work. I'm also assuming that

What to put in precompiled header? (MSVC)

南楼画角 提交于 2019-11-27 10:28:53
问题 What are the best candidates for a precompiled header file? Can I put STL and Boost headers there, even though they have templates? And will that reduce compile times? Also, what are the best IDE settings to reduce compile times? 回答1: The quick answer: the STL and Boost headers do indeed belong in the precompiled header file, even though these header files define template classes. When generating a precompiled header file, a compiler parses the header text (a significant task!), and converts

Using pre-compiled headers with CMake

心已入冬 提交于 2019-11-27 09:04:12
问题 I have seen a few (old) posts on the 'net about hacking together some support for pre-compiled headers in CMake. They all seem a bit all-over the place and everyone has their own way of doing it. What is the best way of doing it currently? 回答1: There is a third party CMake module named 'Cotire' which automates the use of precompiled headers for CMake based build systems and also supports unity builds. 回答2: Im using the following macro to generate and use precompiled headers: MACRO(ADD_MSVC

Weird Behavior with gcc precompiled headers

吃可爱长大的小学妹 提交于 2019-11-27 07:49:22
问题 I was having troubles getting pre-compiled headers to work, so I came up with the following minimal-working-example. This is the header file foo.h #include <iostream> using namespace std; void hello() { cout << "Hello World" << endl; } I compile this as g++ -c foo.h gives me a compiled header foo.gch . I expect that when I compile the following source file that includes foo.h , it should pick the header foo.h.gch and I am good. // test.cpp #include <cstdio> // Swap ordering later #include

include stdafx.h in header or source file?

橙三吉。 提交于 2019-11-27 06:39:56
问题 I have a header file called stdafx.h and this one is precompiled of course. I've read that I should include these files into my .cpp files, but some of these statements are already needed in the header file coming with that. Should I add the stdafx into my header or into my cpp? I thought it was good practise to put it into the header, but I seem to be obliged to put it into the header instead. Example: stdafx contains freeglut. my class header file has an attribute of GLenum. Should I

How to fix PCH error?

纵然是瞬间 提交于 2019-11-27 04:12:22
问题 When I try to build my app in Xcode , I get this error message: PCH file built from a different branch ((clang-425.0.24)) than the compiler ((clang-425.0.27)) It doesn't happen before, but this was the first build after updating Xcode. Other apps work, but not this specific one. If I turn off the "Precompile Prefix Header" setting, it works. How do I fix this error and still keep that setting on? 回答1: This is often a caching problem. Usually it can be resolved by holding down the Option key

How to fix .pch file missing on build?

假如想象 提交于 2019-11-27 02:36:15
When I build my c++ solution in Visual Studio it complains that the xxxxx.pch file is missing. Is there a setting I am missing to get the pre-compiled headers back? here is the exact error for completeness: Error 1 fatal error C1083: Cannot open precompiled header file: 'Debug\xxxxx.pch': No such file or directory NOTE: Later versions of the IDE may use "pch" rather than "stdafx" in the default names for related files. It may be necessary to substitute pch for stdafx in the instructions below. I apologize. It's not my fault. Right-click on your project in the Solution Explorer. Click

Precompiled headers with GCC

白昼怎懂夜的黑 提交于 2019-11-27 02:31:29
Anyone had any success getting precompiled headers working with GCC? I have had no luck in my attempts and I haven't seen many good examples for how to set it up. I've tried on cygwin gcc 3.4.4 and using 4.0 on Ubuntu. I have definitely had success. First, I used the following code: #include <boost/xpressive/xpressive.hpp> #include <iostream> using namespace std; using namespace boost::xpressive; //A simple regex test int main() { std::string hello( "hello world!" ); sregex rex = sregex::compile( "(\\w+) (\\w+)!" ); smatch what; if( regex_match( hello, what, rex ) ) { std::cout << what[0] << '