Find the answer to your Linux question:
Results 1 to 4 of 4
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 ...
  1. #1
    ggf
    ggf is offline
    Just Joined!
    Join Date
    Jan 2010
    Posts
    2

    Question C++ and C name dangling error

    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

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    It is obvious that your are suffering from a case of a missing extern "C" declaration, or there really is a C and C++ version of syslog() defined. If the C++ header is referencing the C version of syslog() as an extern function declaration, then make sure you preceed the declaration in the header with extern "C". Also, you might want to be sure that the syslog.h C header file has a
    Code:
    #ifdef __cplusplus
    extern "C" {
    #endif
    /* C header code here.... */
    .
    .
    .
    #ifdef __cplusplus
    }
    #endif
    block to tell the c++ compiler not to c++ mangle the names it finds.

    In any case, the above problem is common when doing cross-platform ports. Some of the implementations miss this.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    ggf
    ggf is offline
    Just Joined!
    Join Date
    Jan 2010
    Posts
    2
    Yes 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

  4. #4
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    Somewhere in one of your c++ headers (either local application header or system header) there is a declaration for 'void syslog(int, const char*, ...)' that has not been guarded, or is an actual C++ function. That is what the error is indicating. You need to track that down and fix it one way or the other.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...