?
Solved

error while compiling c++ code

Posted on 2008-09-29
10
Medium Priority
?
445 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 2000 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying 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

Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deletiā€¦
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 synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
Suggested Courses

770 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