Solved

error while compiling c++ code

Posted on 2008-09-29
10
431 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

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

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. …
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

840 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