Solved

error while compiling c++ code

Posted on 2008-09-29
10
434 Views
Last Modified: 2013-12-14
I have created VC++ simple Windows Console Application Visual Studio 2005. main puncation just print "hello world" on screen with the help of cout.

Now i want to add .c file which contain funcation . after including that file in project i tred to complie it. But it is giving complie error as follow


"Error      1      fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?c:\my documents\visual studio 2005\projects\try1\try1\try.c      6      
"

please let me know how to solve this problem
0
Comment
Question by:palhade
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
10 Comments
 
LVL 19

Expert Comment

by:alb66
ID: 22595900
Add the following line at the beginning of your file:
#include "stdafx.h"

Otherwise opene the file's property window and in the "Procompiled header" page choose "without precompiled header" option
0
 
LVL 19

Expert Comment

by:alb66
ID: 22595922
For an overview of precompiled headers give a look at:
http://msdn.microsoft.com/en-us/library/szfdksca(VS.80).aspx
0
 

Author Comment

by:palhade
ID: 22595991
thanks for your immediate reply. but now i am getting another following error
Error 1 error C2732: linkage specification contradicts earlier specification for 'myfuncation' c:\my documents\visual studio 2005\projects\try1\try1\try1.cpp 14
 
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 19

Expert Comment

by:alb66
ID: 22596036
If you are calling a "c" fucntion from a "cpp" file you need to declare it as extern "C":

example:

in your .c file:

void func(void)
{
...
}

in your .cpp file

extern "C" void func( void );

int main()
{
  ...
  func();
  ...
}


http://msdn.microsoft.com/en-us/library/726yhbsw(VS.80).aspx
0
 

Author Comment

by:palhade
ID: 22596075
i wrote this
extern "C" void myfuncation( void );
before main() call.
 in my .c file i wrote following code
void myfuncation( void )
{
printf("Hello World");
}
then also i am getting same error
Error 1 error C2732: linkage specification contradicts earlier specification for 'myfuncation' c:\my documents\visual studio 2005\projects\try1\try1\try1.cpp 13

0
 
LVL 19

Expert Comment

by:alb66
ID: 22596106
Check the spelling: did you write myfuncation everyhere or sometimes you wrote myfunction ?
0
 

Author Comment

by:palhade
ID: 22596143
name is same. i right clicked on myfuncation( void ) of following and clicked Go to Defination.
extern "C" void myfuncation( void );
 
It is going to that funcation in .c file.
0
 
LVL 19

Expert Comment

by:alb66
ID: 22596169
What is at try1.cpp line 13?
0
 

Author Comment

by:palhade
ID: 22596276
extern "C" void myfuncation( void );
 
I am also including this .c file by #include "try.c"
0
 
LVL 19

Accepted Solution

by:
alb66 earned 500 total points
ID: 22596319
If you include the .c file in in a .cpp file it will be compiled as cpp code; so you must remove the line
extern "C" void myfuncation( void );
But I don't like this solution.

I'd prefer to compile try.c as a seprate file. So remove #include "try.c" from your .cpp file and add try.c to the project.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question