Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Header file skipped when looking for precompiled header use

Tags:

c++

Could you help me understand what the problem is? I seem to have included stdafx.h. Then I tried to rebuild the solution. Tried to clean the solution. And anyway I get this:

c:\...\tetris\figure_factory.cpp(2): warning C4627: '#include "figure_factory.h"': skipped when looking for precompiled header use
1>          Add directive to 'StdAfx.h' or rebuild precompiled header
1>c:\...\tetris\tetris\figure_factory.cpp(3): warning C4627: '#include "figure.h"': skipped when looking for precompiled header use
1>          Add directive to 'StdAfx.h' or rebuild precompiled header

And of course the full set of mistakes following from the absence of the header files.

My files:

figure_factory.cpp


#pragma once
#include "figure_factory.h"
#include "figure.h"
#include "stdafx.h"
#define stop __asm nop

Figure I;
I.shape = {
            {{0, 0, 0, 0}, 
             {1, 1, 1, 1},
             {0, 0, 0, 0},
             {0, 0, 0, 0}},
......



figure_factory.h

#pragma once
#include "figure.h"
#include "stdafx.h"
#define stop __asm nop


class Figure_Factory{
    const int figure_number = 5; 
    const int colour_number = 5; 

    public:
        Figure get_figure(int type, int colour);
}
like image 741
Trts Avatar asked Dec 30 '25 13:12

Trts


2 Answers

stdafx.h must come as first include file if you are using precompiled headers and Microsoft compiler. And you must not include it in other include files. And #pragma once is useless in .cpp files

like image 182
Loghorn Avatar answered Jan 02 '26 01:01

Loghorn


Here's another possibility: You've got a header file which is marked as a source file. In Visual Studio, right-click the header file and in Configuration Properties > General > Item Type check that you have "C/C++ header", not "C/C++ compiler".

This is an easy mistake to make when manually editing the .vcxproj file, by typing <ClCompile> instead of <ClInclude>.

like image 25
Nanki Avatar answered Jan 02 '26 03:01

Nanki