Can't #include <stdlib.h> on Solaris
I'm working on Solaris x86 and have installed gcc4 using the OpenCSW packages. A simple test program below will not compile:
#include <stdio.h>
#include <stdlib.h>
main()
{
printf("Hello, world\n");
}
It builds and runs fine if I don't have the stdlib.h include. When stdlib.h is in I get the following errors:
开发者_StackOverflowbash-3.00$ g++ -I/opt/csw/include test.cpp
In file included from /opt/csw/gcc4/lib/gcc/i386-pc-solaris2.8/4.3.3/include- fixed/stdlib.h:27,
from test.cpp:2:
/usr/include/iso/stdlib_iso.h:107: error: expected initializer before '__NORETURN'
/usr/include/iso/stdlib_iso.h:124: error: expected initializer before '__NORETURN'
/usr/include/iso/stdlib_iso.h:132: error: multiple parameters named '_RESTRICT_KYWD'
I think this might be some sort of conflict between OpenCSW and the default libraries, but I'm not sure how to fix it. Can anybody help?
Just remove -I/opt/csw/include
from your command line.
Try running one of the fixheaders
or fixincludes
commands that should be part of your gcc installation. There is likely a mismatch between the gcc package which is built for Solaris 8 according to its name and the Solaris release you are running, presumably Solaris 10 or newer.
Can't reproduce on Solaris 10 x86, neither with nor without -I
:
-bash-3.00$ /opt/csw/gcc4/bin/g++ test.cpp
-bash-3.00$ /opt/csw/gcc4/bin/g++ -v
Using built-in specs.
Target: i386-pc-solaris2.10
Configured with: ../gcc-4.3.3/configure --prefix=/opt/csw/gcc4 --exec-prefix=/opt/csw/gcc4 --with-gnu-as --with-as=/opt/csw/bin/gas --without-gnu-ld --with-ld=/usr/ccs/bin/ld --enable-nls --with-included-gettext --with-libiconv-prefix=/opt/csw --with-x --with-mpfr=/opt/csw --with-gmp=/opt/csw --enable-java-awt=xlib --enable-libada --enable-libssp --enable-objc-gc --enable-threads=posix --enable-stage1-languages=c --enable-languages=ada,c,c++,fortran,java,objc
Thread model: posix
gcc version 4.3.3 (GCC)
精彩评论