Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi!

I'm working with Microsoft Visual C++ 6.0.
I want to I included a cs.h file in my C++ code like this:
C++
extern "C"
{
   #include "cs.h" 
}

But, when I use then I have the following error:
d:\program files\microsoft visual studio\vc98\include\math.h(514) : error C2894: templates cannot be declared to have 'C' linkage

Can anyone help?
Thanks in advance. :)
Posted
Updated 13-Aug-10 20:23pm
v2

Doesn't the error message say it all? Your include file is including math.h which contains a template function. Templates aren't C so you can't make them extern "C".

So the big question is why do you want to stick the complete contents of an include file in an extern "C"? If the original programmer had intended his or her code to be used from a C program they'd have done that for you. As they haven't there's one of two options:

- They didn't intend it to be used from a C program
- They did intend it to be used from a C program but not have it compiled by a C++ compiler

Either way the best bet is to modify the source so it doesn't require the client programmer to hack around it.

Cheers,

Ash
 
Share this answer
 
Comments
Xiaohu Shao 14-Aug-10 4:52am    
Hi Aescleal,
Thank you very much for answering this question.I'll try to modify the source code as you say though it seems a little difficult.
Cheers,
Xiaohu Shao
Stefan_Lang 26-Aug-11 5:11am    
On a sidenote, never include another header file in a header file if you can avoid it. It causes all kind of inconveniences, including the one you stumbled upon, but also it affects your compile times. More often than not you can simply move #include statements to the appropriate cpp file instead. Or if you can't, try to use forward declarations. See my tip on that topic, at http://www.codeproject.com/Tips/62486/Improve-compile-times-with-forward-declarations/
i also have the same question !
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900