0

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 :)

1
  • 1
    Small remark: you have different counts: one Count, the other count. Commented Mar 12, 2013 at 11:51

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

0

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.

1 Comment

Thank you very much, it#s the solution :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.