LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   C++ linkage (https://www.linuxquestions.org/questions/programming-9/c-linkage-781964/)

Gracy 01-13-2010 09:26 AM

C++ linkage
 
I am porting a code which ran on HP unix to CentOS. It was a working code and compiled with gcc3.1.x 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

I have the extern "C" included like this . But still I face the same problem . What Am I missing ??

#ifdef __cplusplus
extern "C" {
#endif

#include <syslog.h>
#include <stdarg.h>

#ifdef __cplusplus
}
#endif

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 , Where Am I going wrong ?

johnsfine 01-13-2010 09:48 AM

Unfortunately, nothing in the error text you posted shows the point at which the earlier C++ declaration is included. It only shows the nested includes that reach the C declaration.

If I understand correctly, the C declaration is the one you want and the C++ declaration is the one you don't want.

I assume the code you posted (that includes syslog.h wrapped within extern "C") is in some other header file or is somewhere other than the beginning of the .cpp file in which you get the error.

If you put that code first (either first directly within the .cpp or first withing the .h or .hpp that is included first by the .cpp) things should change. Depending on include guards in the path to the problem, it is possible that the problem would go away by making that code first. More likely, the error messages would reverse and give you details of the C++ declaration rather than the C declaration. Then you could properly diagnose the problem.


All times are GMT -5. The time now is 07:08 AM.