0
votes

I use MSVC2017 (with MSVC2013 toolchain, if it's matters). So, I have created new solution with "static lib" project and a console app. At this step it works.

Now, I changed some project's paths for the lib project:

Output directory: $(SolutionDir)BuildDebug
Intermediate directory: $(OutDir)\Debug
I added following includes into pch.h:

  • #include <windows.h>
  • #include <inttypes.h>
  • #include <cstdlib>
  • #include <stdexcept>

I added reference to my lib and lib's include dir inside console app. Now Studio cannot compile my project, showing a lot of errors about

error C2061: syntax error: identifier 'LONG'

and related. I found that there is no .pch file anywhere. I also created test solution with same static lib alone and changed same paths. It seems to compiling successfully, but Intellisense underlines "LONG" with red, saying "it's undefined". May be someone faced the same problem.

Update: I just tried to create a new solution. I added static lib project, then I added simple file with single function int func(LONG v). It seems to compile. But then I add console app to the solution, link it against static lib, and it's not compile, saying that

error C2065: 'LONG': undeclared identifier

Update 2: I've found that static lib files don't see <windows.h> added into precompiled header. So I included it into my header directly and added typedef struct IUnknown IUnknown; before windows.h, because of new error related to IUnknown. It seems to work. But I still don't understand what is going on.

1

1 Answers

1
votes

"Pre-compiled headers" are a build-speed optimization. If they're giving you problems, you can always turn off their use temporarily. When they're turned off, the .pch is no longer used, but the .h is still used.

I expect you'll still have the missing LONG, since it's not even in the .h

For your sanity, it might be useful to use explicit names for your precompiled .h. I'm not sure if VS2017 already uses pch.h by default, or it it still uses stdafx.h. Either way, that's just a default. If you want, you can also rename them to staticlib.h/.pch and executable.h/.pch to avoid confusion. The compiler has no default name for the pch; it relies on compiler switches /Yc (create) and /Yu (use).