0
votes

I have tried to create multiple Cpp files on visual studio 2012, my code parts are here:

externTest.ccp

// externTest.cpp : Defines the entry point for the console application.
//
#include "...\externTest\externTest\write.h"
//////////////////
// Global variables
/////////////////
int Count = 5;
/////////////////
// Extern functions
/////////////////
extern void write_extern ();
int main()
{
    int count = Count;
    write_extern();
    getchar ();
    return 0;
}

write.h

#ifndef WRITE_H
#define WRITE_H

////////////////////////
// Includes
////////////////////////
#include "stdafx.h"
#include <iostream>
using namespace std;
////////////////////////
// Variables
////////////////////////
extern int count;
////////////////////////
// Function prototype
////////////////////////
void write_extern (void);
///////////////////////
#endif // !WRITE_H

write.cpp

// write.ccp
//////////////////
// Includes
/////////////////
#include <...\externTest\externTest\write.h>
////////////////////
// Functions definition
////////////////////
void write_extern ()
{
    cout<< "Count is: \t" << count;
}

Finally get the following error, which is basically not recognizing the write.h file even I that the path is correctly defined:

falouji\documents\visual studio 2012\projects\externtest\externtest\write.cpp(5): warning C4627: '#include <...\externTest\externTest\write.h>': skipped when looking for precompiled header use 1> Add directive to 'stdafx.h' or rebuild precompiled header

Finally thanks in advance for your help :)

2
Small remark: you have different counts: one Count, the other count.Aneri

2 Answers

2
votes

You either have to include stdafx.h, or disable precompiled headers in the project options.

0
votes

You have made a project that uses precompiled headers, so compiler looks for #include "stdafx.h" line as first include in the .cpp files, you can change this in the following way:

1) Right click the file in the solution view and open properties

2) Expand the C/C++ subsection

3) Under Precompiled Headers and set Create/Use Precompiled Header to Not Using Precompiled Headers

Or just make an empty project and add your files to it, whichever is best.