Solved

error while compiling c++ code

Posted on 2008-09-29
10
426 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
  • 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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.
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

911 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now