How can I differentiate C and C++ compiler?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I want a user to set environment variables CC and CXX and point them to C and C++ compilers. I want to check that they are in fact C and C++ compilers, and that CC does not point to a C++ compiler, and CXX does not point to a C compiler.

I've done this on HP-UX, using HP's native compiler, using:

echo "#ifdef __HP_aCC"                   >> $TESTFILE
echo "error_this_is_C++_not_C_compiler"  >> $TESTFILE
echo "#endif"                            >> $TESTFILE


${CC} -E $TESTFILE | grep error_this_is_C++_not_C_compiler >/dev/null 2>&1
if [ $? = 0 ]; then
   echo Error_C++_not_C_compiler
   rm $TESTFILE
   exit 0
fi


That works, since HP's C++ compiler defines __HP_aCC, but the C compiler does not. (HP's C compiler on AIX defines __HP_cc instead).


Is there anything I can do with gcc/g++ to do this? I know they both define __GNU__, but that does not help me.

I really only need to work for gcc/g++ >= 3.4.0, but it would handy if it worked for any gcc.


Dave

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux