3 Replies Latest reply: Apr 24, 2014 7:22 AM by user4273027 RSS

    CC Compilation error in stdlib.h [The function "__asm" must have a prototype]

    user4273027

      I have encountered a strange error while comping my cpp program which is having the "stdlib.h" library included using the "CC" compiler in RHEL 6.4 server with kernel version 2.6.32-358.el6.x86_64. Below is the error and a sample program to reproduce the error.

       

      cat samplestdlib.cc

      -----------

      #include <iostream.h>

      #include <stdlib.h>

      main()

      {

      cout <<"Hello"<<endl;

       

      }

      ----------

       

      While compiling this program with _GNU_SOURCE enabled, I am getting the below error. The compilation option I used is

      :CC -m32 -D_GNU_SOURCE samplestdlib.cc

       

      "/usr/include/stdlib.h", line 526: Error: "{" expected instead of "__asm".

      "/usr/include/stdlib.h", line 526: Error: The function "__asm" must have a prototype.

      "/usr/include/stdlib.h", line 964: Error: "at_quick_exit(void(*)())" is expected to return a value.

      "/data/applns/sunstudio12/prod/include/cc/stdlib.h", line 57: Error: exit is not defined.

      "/data/applns/sunstudio12/prod/include/cc/stdlib.h", line 58: Error: getenv is not defined.

      "/data/applns/sunstudio12/prod/include/cc/stdlib.h", line 59: Error: system is not defined.

      "/data/applns/sunstudio12/prod/include/cc/stdlib.h", line 60: Error: bsearch is not defined.

      "/data/applns/sunstudio12/prod/include/cc/stdlib.h", line 61: Error: qsort is not defined.

      "/data/applns/sunstudio12/prod/include/cc/stdlib.h", line 62: Error: abs is not defined.

      "/data/applns/sunstudio12/prod/include/cc/stdlib.h", line 63: Error: labs is not defined.

      "/data/applns/sunstudio12/prod/include/cc/stdlib.h", line 64: Error: div is not defined.

      "/data/applns/sunstudio12/prod/include/cc/stdlib.h", line 65: Error: ldiv is not defined.

      "/data/applns/sunstudio12/prod/include/cc/stdlib.h", line 66: Error: mblen is not defined.

      "/data/applns/sunstudio12/prod/include/cc/stdlib.h", line 67: Error: mbtowc is not defined.

      "/data/applns/sunstudio12/prod/include/cc/stdlib.h", line 68: Error: wctomb is not defined.

      "/data/applns/sunstudio12/prod/include/cc/stdlib.h", line 69: Error: mbstowcs is not defined.

      "/data/applns/sunstudio12/prod/include/cc/stdlib.h", line 70: Error: wcstombs is not defined.

      "/data/applns/sunstudio12/prod/include/cc/stdlib.h", line 79: Error: The function "labs" must have a prototype.

      "/data/applns/sunstudio12/prod/include/cc/stdlib.h", line 80: Error: The function "ldiv" must have a prototype.

      "/data/applns/sunstudio12/prod/include/CC/new", line 32: Error: operator new(unsigned) was declared before with a different language.

      "/data/applns/sunstudio12/prod/include/CC/new", line 35: Error: operator delete(void*) was declared before with a different language.

      "/data/applns/sunstudio12/prod/include/CC/new", line 37: Error: operator new[](unsigned) was declared before with a different language.

      "/data/applns/sunstudio12/prod/include/CC/new", line 40: Error: operator delete[](void*) was declared before with a different language.

      "/data/applns/sunstudio12/prod/include/CC/new", line 53: Error: Only one of a set of overloaded functions can be extern "C".

      "/data/applns/sunstudio12/prod/include/CC/new", line 54: Error: Only one of a set of overloaded functions can be extern "C".

      Compilation aborted, too many Error messages.

       

      My sunstudio version, OS details and CC versions are as shown below

      :sunstudio -V

      Sun Studio IDE 8.0 Linux_i386 2007/05/03

       

      :CC -V

      CC: Sun C++ 5.9 Linux_i386 2007/05/03

       

      :uname -a

      Linux serv.dev2 2.6.32-358.el6.x86_64 #1 SMP Tue Jan 29 11:47:41 EST 2013 x86_64 x86_64 x86_64 GNU/Linux

       

      :rpm -qf /usr/bin/g++

      gcc-c++-4.4.7-3.el6.x86_64

       

      Is it that this version of CC compiler doesn't support the "__asm" in stdlib.h ? I can compile and Run the same code using g++ with out any issues. Can you please suggest the problem here and  a possible solution.