C++ Learning Community Forum
September 09, 2010, 08:17:06 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Hello. Smiley
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Name Conflicts between C++ and C  (Read 290 times)
GGF
N00b!!1
*
Posts: 1


View Profile
« on: January 08, 2010, 05:49:24 PM »

I am porting a code which ran on HP unix to CentOS. It was a working code and a c++ file and now I tried to compile with gcc3-3.4.6 and gcc4-4.2.4 also. But still I get this conflicts in declaration error as pasted below.

In file included from ../../../lol/ntk/nt_kslog.h:155,
from ../../../lol/ntk/nt_kernel.h:243,
from ../../../lol/ntk/nt_cp.h:110,
from ../../../soml/include/soml-afi-afu.h:131,
from ../../include/pcdb.h:58,
from ../../include/pcdb_addtypes.h:59,
from pcdb_addtypes.cc:94:

/opt/bcs/include/syslog.h:93: error: previous declaration of 'void syslog(int, const char*, ...)' with 'C++' linkage
/opt/bcs/include/syslog.h:93: error: conflicts with new declaration with 'C' linkage

Here pcdb.h , pcdb_addtypes.h are c++ headers and rest are C headers and I see that proper extern is mentioned in pcdb.h for soml-afi-afu.h. Also syslog is a declaration which I cannot make it extern as I cant change the code. My code is only the C++ part and is the files mentioned above?

Also , I work on Centos 5 box and it compiled without any issues on one machine and the same throws this error on other box with centos and both compilers.

Could anyone please help me as I am in a very hurry to solve this ? Where Am I going wrong ?

Please help.

-GGF
Logged
myork
Global Moderator
C++ guru
*****
Posts: 1147


View Profile
« Reply #1 on: January 09, 2010, 09:33:35 PM »


If you are going to use a C++ compiler to compile C source then the C header files should have the following at the top:

Code:
#ifdef  __cplusplus
extern "C" {
#endif

// All the normal file stuff

#ifdef __cplusplus
}
#endif
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!