Solved

error while compiling c++ code

Posted on 2008-09-29
10
418 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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.
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 use and create keystrokes in Netbeans IDE 8.0 for Windows.

747 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

15 Experts available now in Live!

Get 1:1 Help Now