7 Replies Latest reply on Apr 1, 2010 3:21 PM by 807575

    Strange C++ error when using newer Sun Studio compiler

    807575
      My company has just set up a new build machine for our product. We have gone from

      this version: CC: Sun C++ 5.7 Patch 117830-11 2007/04/04

      to this one: CC: Sun C++ 5.9 SunOS_sparc Patch 124863-01 2007/07/25

      we have also upgraded the OS (solaris/sparc). I think the new one has gcc but the old one doesn't (we don't use it).

      and now I am getting this error:

      "/opt/SUNWspro/prod/include/CC/./new", line 32: Error, badextlnk: operator new(unsigned) was declared before with a different language.
      "/opt/SUNWspro/prod/include/CC/./new", line 35: Error, badextlnk: operator delete(void*) was declared before with a different language.
      "/opt/SUNWspro/prod/include/CC/./new", line 37: Error, badextlnk: operator new[](unsigned) was declared before with a different language.
      "/opt/SUNWspro/prod/include/CC/./new", line 40: Error, badextlnk: operator delete[](void*) was declared before with a different language.
      "/opt/SUNWspro/prod/include/CC/./new", line 53: Error, badollnk: Only one of a set of overloaded functions can be extern "C".
      "/opt/SUNWspro/prod/include/CC/./new", line 54: Error, badollnk: Only one of a set of overloaded functions can be extern "C".
      "/opt/SUNWspro/prod/include/CC/./new", line 55: Error, badollnk: Only one of a set of overloaded functions can be extern "C".
      "/opt/SUNWspro/prod/include/CC/./new", line 56: Error, badollnk: Only one of a set of overloaded functions can be extern "C".
      "/opt/SUNWspro/prod/include/CC/Cstd/rw/iterator", line 106: Error, temnotexternc: Template declarations cannot have extern "C" linkage.
      "/opt/SUNWspro/prod/include/CC/Cstd/rw/iterator", line 169: Error, temnotexternc: Template declarations cannot have extern "C" linkage.
      "/opt/SUNWspro/prod/include/CC/Cstd/rw/iterator", line 185: Error, temnotexternc: Template declarations cannot have extern "C" linkage.
      "/opt/SUNWspro/prod/include/CC/Cstd/rw/iterator", line 198: Error, temnotexternc: Template declarations cannot have extern "C" linkage.
      "/opt/SUNWspro/prod/include/CC/Cstd/rw/iterator", line 202: Error, temnotexternc: Template declarations cannot have extern "C" linkage.
      "/opt/SUNWspro/prod/include/CC/Cstd/rw/iterator", line 206: Error, temnotexternc: Template declarations cannot have extern "C" linkage.
      "/opt/SUNWspro/prod/include/CC/Cstd/rw/iterator", line 217: Error, badollnk: Only one of a set of overloaded functions can be extern "C".
      "/opt/SUNWspro/prod/include/CC/Cstd/rw/iterator", line 225: Error, temnotexternc: Template declarations cannot have extern "C" linkage.
      "/opt/SUNWspro/prod/include/CC/Cstd/rw/iterator", line 239: Error, temnotexternc: Template declarations cannot have extern "C" linkage.
      "/opt/SUNWspro/prod/include/CC/Cstd/rw/iterator", line 249: Error, temnotexternc: Template declarations cannot have extern "C" linkage.
      "/opt/SUNWspro/prod/include/CC/Cstd/rw/iterator", line 264: Error, temnotexternc: Template declarations cannot have extern "C" linkage.
      "/opt/SUNWspro/prod/include/CC/Cstd/rw/iterator", line 275: Error, temnotexternc: Template declarations cannot have extern "C" linkage.

      I have no idea what could be causing this. I can find one link to it on this forum: http://forums.sun.com/thread.jspa?messageID=9488983 . But the only answer to that query says it is the same as another bug which appears entirely different, not to mention being very old (while talking about an imminent fix), and being related to a different OS and (I think) a different version of sun studio (express vs. normal?).

      Any ideas? Could it be related to having gcc/g++ on the machine?
        • 1. Re: Strange C++ error when using newer Sun Studio compiler
          807575
          Possibly you have included system headers inside
          extern "C" { ... }  
          brackets, although that should have resulted in similar errors using the older compiler and OS.

          You can check for that, but in the mean time, please provide a little more information:

          What OS version are you now using? Please run the command
          uname -a

          Please show the full CC command line that results in the error message.

          Edited by: clamage45 on Jul 27, 2008 10:59 AM
          • 2. Re: Strange C++ error when using newer Sun Studio compiler
            807575
            Hi,

            I am also facing the same error while upgrading the Sun compiler description as below

            when I am compiling the cxx file on the system with compiler version (CC: Sun C++ 5.9 SunOS_sparc 2007/05/03) , I am facing the following error:-

            /opt/SUNWspro/bin/CC -dy -misalign -xcode=abs64 -xarch=v9 -D__EXTENSIONS__ -Dsun4_R5=1 -I. -Isun4_R5_v -I/home/as185259/ash_iadraid/ash_get_10/IA/PORT/include -I/home/as185259/ash_iadraid/ash_get_10/IA/WV/WV5.3.6-ncr0302/build/include/sun4_R5_v -I/app/oracle/product/10.2.0/client_1/sqllib/public -I/app/oracle/product/10.2.0/client_1/precomp/public -I/opt/informix/include -DSVR4 -O -g p -pta -c MContext.cxx -o sun4_R5_v/MContext.o || \
            (rm -f sun4_R5_v.d; false)CC: Warning: -xarch=v9 is deprecated, use -m64 to create 64-bit programs
            "/home/as185259/ash_iadraid/ash_get_10/IA/WV/WV5.3.6-ncr0302/build/include/sun4_R5_v/ssmalloc.h", line 97: Error: Only one of a set of overloaded functions can be extern "C".
            "/home/as185259/ash_iadraid/ash_get_10/IA/WV/WV5.3.6-ncr0302/build/include/sun4_R5_v/ssmalloc.h", line 99: Error: Only one of a set of overloaded functions can be extern "C".
            "/home/as185259/ash_iadraid/ash_get_10/IA/WV/WV5.3.6-ncr0302/build/include/sun4_R5_v/ssmalloc.h", line 101: Error: Only one of a set of overloaded functions can be extern "C".
            "/home/as185259/ash_iadraid/ash_get_10/IA/WV/WV5.3.6-ncr0302/build/include/sun4_R5_v/ssmalloc.h", line 102: Error: Only one of a set of overloaded functions can be extern "C".
            4 Error(s) detected.


            The same file with the same compilation command is getting compiled with compiler version CC: Sun WorkShop 6 update 2 C+ 5.3 2001/05/15 .
            Can anyone suggest what should be the resolution:-

            The code for the ssmalloc.h file is as under:-

            #ifndef SSMALLOC_H
            #define SSMALLOCH

            #include <stddef.h>

            #if defined(__sparcv9)
            namespace ssmalloc {
            #endif
            #if defined(__cplusplus)
            extern "C" {
            #endif

            /
            The type for the malloc routine depends on
            the compiler and library that you are using.
            /
            #if defined(hpux) || defined(sun4_R5) || defined(__GNUC_) || defined(_OS2_)
            typedef void MALLOC_PTR;
            #else
            typedef char *MALLOC_PTR;
            #endif

            #if defined(_GNUG_)
            typedef size_t MALLOC_SIZE;
            #else
            typedef unsigned MALLOC_SIZE;
            #endif

            #if defined(sun4) && ! defined(_GNUG_)
            # define FREE_RETURNS int
            # define FREE_RETURN return 0
            #else
            # define FREE_RETURNS void
            # define FREE_RETURN return
            #endif


            //
            //
            // User-callable routines.
            //
            //
            // Note: memalign and valloc are broken in that they do not aling
            // memory on documented boundaries, and thus do not behave as described
            // on the "malloc" manual page. They simply call malloc.
            //
            //
            MALLOC_PTR malloc (MALLOC_SIZE size);
            FREE_RETURNS free (MALLOC_PTR data);
            MALLOC_PTR realloc (MALLOC_PTR data, MALLOC_SIZE size);
            MALLOC_PTR calloc (size_t nelem, size_t elsz);
            MALLOC_PTR valloc (unsigned size);
            MALLOC_PTR memalign (unsigned alignment, unsigned size);

            //
            // This memory allocator supports memory allocation inside signal
            // handlers. For correct operation, the following functions must be
            // called upon entering and exiting signal handlers that allocate
            // memory.
            //

            void ssmalloc_enter_signal_level();
            void ssmalloc_exit_signal_level();

            //
            // Set this variable to not 0 (possibly in the debugger) if you want
            // to get malloc to check memory data structures very carefully as it
            // goes. This may be handy if you are trying to detect a memory
            // trasher.
            //
            // It also causes ssmalloc to abort the program instead of returning
            // zero if memory runs out.
            //
            extern int check_memory_very_carefully;

            #if defined(__cplusplus)
            }
            #endif

            #if defined(__sparcv9)
            } // namespace ssmalloc {
            #endif
            #endif / SSMALLOCH */

            The Machine is
            root@ldg1-> uname -a
            SunOS ldg1 5.10 Generic_138888-03 sun4v sparc SUNW,Sun-Blade-T6320

            Thanks
            Vijay
            • 3. Re: Strange C++ error when using newer Sun Studio compiler
              807575
              Please re-post source code of ssmalloc.h using CODE tag; right now it is only 83 lines long while compiler starts complaining at line 97...
              • 4. Re: Strange C++ error when using newer Sun Studio compiler
                807575
                Thanks for your Reply
                Here is the ssmalloc.h
                #ifndef _SSMALLOC_H
                #define _SSMALLOC_H
                
                #include <stddef.h>
                
                #ifdef __sparcv9
                namespace ssmalloc {
                #endif
                #ifdef __cplusplus
                extern "C" {
                #endif
                
                /*
                 * The type for the malloc routine depends on
                 * the compiler and library that you are using.
                 */
                #if defined(hpux) || defined(sun4_R5) || defined(__GNUC__) || defined(__OS2__)
                typedef void *MALLOC_PTR;
                #else
                typedef char *MALLOC_PTR;
                #endif
                
                #if defined(__GNUG__)
                typedef size_t MALLOC_SIZE;
                #else
                typedef unsigned MALLOC_SIZE;
                #endif
                
                #if defined(sun4) && ! defined(__GNUG__)
                # define FREE_RETURNS   int
                # define FREE_RETURN    return 0
                #else
                # define FREE_RETURNS   void
                # define FREE_RETURN    return
                #endif
                
                
                //
                //
                // User-callable  routines.
                //
                //
                // Note: memalign and valloc are broken in that they do not aling
                // memory on documented boundaries, and thus do not behave as described
                // on the "malloc" manual page. They simply call malloc.
                //
                //
                MALLOC_PTR   malloc   (MALLOC_SIZE size);
                FREE_RETURNS free     (MALLOC_PTR data);
                MALLOC_PTR   realloc  (MALLOC_PTR data, MALLOC_SIZE size);
                MALLOC_PTR   calloc   (size_t nelem, size_t elsz);
                MALLOC_PTR   valloc   (unsigned size);
                MALLOC_PTR   memalign (unsigned alignment, unsigned size);
                
                //
                // This memory allocator supports memory allocation inside signal
                // handlers. For correct operation, the following functions must be
                // called upon entering and exiting signal handlers that allocate
                // memory.
                //
                
                void ssmalloc_enter_signal_level();
                void ssmalloc_exit_signal_level();
                
                //
                // Set this variable to not 0 (possibly in the debugger) if you want
                // to get malloc to check memory data structures very carefully as it
                // goes. This may be handy if you are trying to detect a memory
                // trasher.
                //
                // It also causes ssmalloc to abort the program instead of returning
                // zero if memory runs out.
                //
                extern int check_memory_very_carefully;
                
                #ifdef __cplusplus
                }
                #endif
                
                #ifdef __sparcv9
                } // namespace ssmalloc {
                #endif
                #endif /* _SSMALLOC_H */
                when I tried to use -compat flag compilation has moved forward
                • 5. Re: Strange C++ error when using newer Sun Studio compiler
                  807575
                  The file you show has 84 lines, but the compiler is complaining about lines 97 through 102. Either this is not the same file, or you have not posted the entire file. I don't know how to relate the error messages to the file as shown.

                  The problem is almost certainly that you have different declarations for what is probably supposed to be the same function. For example
                  void foo(unsigned);
                  void foo(size_t); // not the same as unsigned int in 64-bit mode
                  The compiler knows only that they can't both be declared extern "C". Only you can decide if these are different functions, in which case at most can be declared extern "C", or that they are the same function, in which case the declarations must match.
                  • 6. Re: Strange C++ error when using newer Sun Studio compiler
                    807575
                    I am Sorry but there was some copyright message hence I removed those comments here
                    below is the line 97,98,.....102
                    MALLOC_PTR   malloc   (MALLOC_SIZE size);
                    FREE_RETURNS free     (MALLOC_PTR data);
                    MALLOC_PTR   realloc  (MALLOC_PTR data, MALLOC_SIZE size);
                    MALLOC_PTR   calloc   (size_t nelem, size_t elsz);
                    MALLOC_PTR   valloc   (unsigned size);
                    MALLOC_PTR   memalign (unsigned alignment, unsigned size);
                    This same code worked with the older Sun WorkShop 6 update 2 C+ 5.3 2001/05/15 but not with newer cc: Sun C 5.9 SunOS_sparc 2007/05/03

                    Thanks,
                    Vijay

                    Edited by: Koolvc on Mar 31, 2010 10:47 PM
                    • 7. Re: Strange C++ error when using newer Sun Studio compiler
                      807575
                      These functions are evidently declared in more than one place, and the declarations do not match. You will have to track down the place where the conflicting declarations appear and find a way to correct the mis-match.

                      Start with the command line that results in the error messages. Replace -c with -E, remove any -o option, and direct the output to a file. Example:
                      Original command line:
                      CC ... -c foo.cc -o bindir/foo.o
                      Modified command line
                      CC ... -E foo.cc > foo.txt

                      The output file will be fully pre-processed, so you will see only the lines that are actually processed by the compiler. You will also be able to tell where every line of code came from.

                      Look for every declaration of malloc (for example) and see where the differing declarations come from. By relating these declarations back to the original source files, you can see what caused the mismatch -- such as an inappropriate macro definition causing the wrong branch of conditional code to be used -- and figure out a solution.