Why does Eclipse think clang doesn't support std::atomic - c++

I have an eclipse c++ project that uses some c++11 features. It uses cmake for building so it is setup in eclipse as a project with existing makefiles.
It builds fine with the makefiles either in eclipse or from the command line. But I get syntax errors with atomic_bool saying the symbol can't be resolved. I have added -std=c++11 under 'C/C++ General -> Preprocessor Include Pattern -> Providers -> CDT GCC Built-in Compiler Settings' and I have the toolchain in eclipse set to MacOSX GCC.
Note: other c++11 things like thread or shared_ptr don't give any syntax errors.
The errors come from the <atomic> header where there is the preprocessor if statement
#if !__has_feature(cxx_atomic)
#error <atomic> is not implemented
#else
...
Everything below the #else is grayed out. So apparently __has_feature(cxx_atomic) evaluates to 0 according to eclipse. But if I check it from the command line it shows that it should evaluate to true.
$ echo '__has_feature(cxx_atomic)' | g++ -x c++ -std=c++11 -E -
# 1 "<stdin>"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 188 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "<stdin>" 2
1
Why does __has_feature(cxx_atomic) evaluate to false in Eclipse but not if I check the compiler itself?

Try a Enabling "Build output parser".
http://www.eclipse.org/forums/index.php/t/501479/

I encountered this issue too, other C++11 features are supported, but atomic does not.

Related

How to determine compiler name or vendor in Autoconf?

I'm working on Solaris with SunCC. Autoconf's AC_COMPILE_IFELSE and AC_LINK_IFELSE are misdetecting compiler features. Autoconf is reporting features are available even though the compiler rejects them with messages such as illegal option.
$ echo 'int main(int argc, char* argv[]) {}' > test.C
$ /opt/solarisstudio12.4/bin/CC test.C
$ /opt/solarisstudio12.4/bin/CC -msse4.2 -msha test.C
CC: Warning: Option -msse4.2 passed to ld, if ld is invoked, ignored otherwise
CC: Warning: Option -msha passed to ld, if ld is invoked, ignored otherwise
ld: fatal: option '-h a' is incompatible with building a dynamic executable
$ /opt/solarisstudio12.4/bin/CC -xarch=sha test.C
CC: Warning: illegal use of -xarch option, illegal value ignored: sha
I'd like to try to workaround the misdetections, but I need to know the compiler to do it. Autoconf has some macros that provide canonicalized names for CPU, Vendor and OS, but they do not appear to include the compiler or its vendor.
How do we detect or determine compiler name or vendor in Autoconf?
Adding the following is not really helpful since it does not identify the compiler.
AC_MSG_NOTICE(["Build: $build"])
AC_MSG_NOTICE(["Compiler: $compiler"])
Then:
CXX=/opt/solarisstudio12.4/bin/CC ./configure
...
configure: "Build: i386-pc-solaris2.11"
configure: "Compiler: /opt/solarisstudio12.4/bin/CC"
I don't think there is a standard way to do this.
We manually check for the existence of compiler macros according to predef.sourceforge.net and perhaps more sources like cc --version, the cc's command name, the operating system name, ...).
I.e. you compile a program, and check for defines.
If it doesn't exist / the programm #errors out -> not SunCC.
It looks messy, but here is an example straight from the Score-P source (vendor/common/build-config/m4/ax_compiler_vendor.m4). Maybe you can take some inspiration from it:
AC_DEFUN([AX_COMPILER_VENDOR],
[AC_CACHE_CHECK([for _AC_LANG compiler vendor], ax_cv_[]_AC_LANG_ABBREV[]_compiler_vendor,
dnl Please add if possible support to ax_compiler_version.m4
[# note: don't check for gcc first since some other compilers define __GNUC__
vendors="intel: __ICC,__ECC,__INTEL_COMPILER
ibm: __xlc__,__xlC__,__IBMC__,__IBMCPP__
pathscale: __PATHCC__,__PATHSCALE__
clang: __clang__
cray: _CRAYC
fujitsu: __FUJITSU
gnu: __GNUC__
sun: __SUNPRO_C,__SUNPRO_CC
hp: __HP_cc,__HP_aCC
dec: __DECC,__DECCXX,__DECC_VER,__DECCXX_VER
borland: __BORLANDC__,__CODEGEARC__,__TURBOC__
comeau: __COMO__
kai: __KCC
lcc: __LCC__
sgi: __sgi,sgi
microsoft: _MSC_VER
metrowerks: __MWERKS__
watcom: __WATCOMC__
portland: __PGI
tcc: __TINYC__
unknown: UNKNOWN"
for ventest in $vendors; do
case $ventest in
*:) vendor=$ventest; continue ;;
*) vencpp="defined("`echo $ventest | sed 's/,/) || defined(/g'`")" ;;
esac
AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[
#if !($vencpp)
thisisanerror;
#endif
])], [break])
done
ax_cv_[]_AC_LANG_ABBREV[]_compiler_vendor=`echo $vendor | cut -d: -f1`
])
])
As #Ronny stated, there does not appear to be a standard way to determine the compiler vendor. Detecting a vendor is important during configure for tasks like working around Autoconf bugs during misdetection: CC: Warning: illegal use of -xarch option, illegal value ignored: sha.
#Ronny showed how to do it with preprocessor macros. We avoided that because of the way compilers pretend to be GCC. Both Clang and Intel's compiler defines __GNUC__, and probably others do it, too.
Here's how to do it with version strings in configure.ac:
## Determine the compiler's vendor.
COMPILER_VERSION=`"$CXX" --version 2>/dev/null`
## IBM xlC test if COMPILER_VERSION is empty
if test x"$COMPILER_VERSION" = "x"; then
COMPILER_VERSION=`"$CXX" -qversion 2>/dev/null`
fi
## SunCC test if COMPILER_VERSION is empty
if test x"$COMPILER_VERSION" = "x"; then
COMPILER_VERSION=`"$CXX" -V 2>&1`
fi
Then, the vendor can be used like:
IS_SUN_COMPILER=`echo $COMPILER_VERSION | $EGREP -i -c -E 'Sun C\+\+'`
echo "IS_SUN_COMPILER: $IS_SUN_COMPILER"
...
## This block handles SunCC.
if test "$IS_SUN_COMPILER" -ne "0"; then
...
fi

[error]cannot find -lpthread collect2.exe: error: ld returned 1 exit status [duplicate]

I get a bizzare error after upgrading to MinGW 5.3.0-2(actual version)
I checked everything because It's the 5th time i reinstall it and thought it would help
Code::Blocks outputs this:
mingw32-g++.exe -Wall -fexceptions -g -c C:\Users\Tudor\Documents\C++\test\main.cpp -o obj\Debug\main.o
mingw32-g++.exe -o bin\Debug\test.exe obj\Debug\main.o
c:/mingw/bin/../lib/gcc/mingw32/5.3.0/../../../../mingw32/bin/ld.exe: cannot find -lpthread
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 0 second(s))
2 error(s), 0 warning(s) (0 minute(s), 0 second(s))
Note: if I check the -std=c++11 OR -std=c++14 flags i get output like here: Click me
Is it a problem with the last version of MinGW? If so where can I get the last working version? Or is anything in my computer messed up? I would like to keep this version if its possible to fix it but its getting me crazy
You haven't installed the Posix Threads (pthread) library, so the linker
can't find it. The particular Windows GCC packager that you have chosen doesn't
install it by default.
Start the MinGW Installation Manager and navigate All Packages -> MinGW
-> MinGW Standard Libraries. In the Standard Libraries presented, select
mingw32-pthreads-w32 dev. Then from the menubar select Installation -> Apply Changes
and proceed. Make it look like
Newer Windows GCC packagers, e.g. mingw-w64
or TDM-GCC, will install pthreads by default and
provide 64- as well as 32-bit compilers. mingw-w64 in addition offers more up-to-date
versions of GCC (currently 6.2, which is the latest GCC release).
If you use codeblocks-16.01-nosetup version or the earlier similar version then you need to install MinGW in home directory of C drive (C:\MinGW) and you have to add "C:\MinGW\bin" in the system variable called "Path".
However, I would recommend to use "codeblocks-16.01mingw-setup.exe" version of codeblocks. This has a preloaded MinGW latest version. you can get it from here: https://sourceforge.net/projects/codeblocks/files/Binaries/16.01/Windows/codeblocks-16.01mingw-setup.exe/download

How to generate *.f90 files from *.F90 files in gfortran?

I have a small fortran program with some pre-processor directives written in a *.F90 file. Now, I would like to generate a *.f90 fortran file from it, which removes all the extra code in the *.F90 file corresponding to the other non-activated directives.
In pgifortran, all I have to do is :
pgf90 -F file_name.F90
And that is it! It produces a *.f90 file having the lines relevant to the active directives.
How can I do this in gfortran?
GNU Fortran options
See https://gcc.gnu.org/onlinedocs/gfortran/Preprocessing-Options.html for full details, but you may observe that the option -E preprocesses foo.F90 to stdout (you can, of course, pipe it to e.g. foo.f90).
The -E option is valid for the GNU compiler front-ends in general, and works for C, C++ and Fortran.
While preprocessing is enabled by default for files with the extentions .fpp, .FPP, .F, .FOR, .FTN, .F90, .F95, .F03 or .F08, you can enable it manually with -cpp. You can also disable it manually with -nocpp.
Example Program
program main
implicit none
#ifdef USER_MACRO
print*,'USER_MACRO was defined'
#endif
#ifdef __GFORTRAN__
print*,'I am GNU Fortran (aka gfortran)!'
#endif
#ifdef __GNUC__
print*,'I am GNU C (or its preprocessor)!'
#endif
end program main
Result from GNU C preprocessor (cpp)
$ cpp -E fpp.F90
# 1 "fpp.F90"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 324 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "fpp.F90" 2
program main
implicit none
print*,'I am GNU C (or its preprocessor)!'
end program main
Result from GNU Fortran
$ gfortran -E fpp.F90
# 1 "fpp.F90"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "fpp.F90"
program main
implicit none
print*,'I am GNU Fortran (aka gfortran)!'
print*,'I am GNU C (or its preprocessor)!'
end program main
Obviously, you can see how user-defined symbols are preprocessed, too:
$ gfortran -E -DUSER_MACRO fpp.F90
# 1 "fpp.F90"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "fpp.F90"
program main
implicit none
print*,'USER_MACRO was defined'
print*,'I am GNU Fortran (aka gfortran)!'
print*,'I am GNU C (or its preprocessor)!'
end program main
Result from Intel Fortran
In case it is of interest, Intel compilers support the same options as GCC:
$ ifort -E -DUSER_MACRO fpp.F90
# 1 "fpp.F90"
program main
implicit none
print*,'USER_MACRO was defined'
# 8
# 11
end program main
Preprocessing with IBM XL Fortran
The IBM XL Fortran man pages have the full details, but it is important to note that preprocessor symbols must be provided via -WF,-DUSER_MACRO instead of -DUSER_MACRO.

compile aosp 32 bit linux

looking to compile 4.4.2 aosp source following the guide https://groups.google.com/forum/#!topic/android-building/xFtX6K42BDE. why is host not compiling properly?
Install: /home/brandonabandon/sn/out/host/linux-x86/bin/acp
host StaticLib: libbz (/home/brandonabandon/sn/out/host/linux-x86/obj/STATIC_LIBRARIES/libbz_intermediates/libbz.a)
prebuilts/tools/gcc-sdk/ar crsP /home/brandonabandon/sn/out/host/linux-x86/obj/STATIC_LIBRARIES/libbz_intermediates/libbz.a /home/brandonabandon/sn/out/host/linux-x86/obj/STATIC_LIBRARIES/libbz_intermediates/blocksort.o /home/brandonabandon/sn/out/host/linux-x86/obj/STATIC_LIBRARIES/libbz_intermediates/huffman.o /home/brandonabandon/sn/out/host/linux-x86/obj/STATIC_LIBRARIES/libbz_intermediates/crctable.o /home/brandonabandon/sn/out/host/linux-x86/obj/STATIC_LIBRARIES/libbz_intermediates/randtable.o /home/brandonabandon/sn/out/host/linux-x86/obj/STATIC_LIBRARIES/libbz_intermediates/compress.o /home/brandonabandon/sn/out/host/linux-x86/obj/STATIC_LIBRARIES/libbz_intermediates/decompress.o /home/brandonabandon/sn/out/host/linux-x86/obj/STATIC_LIBRARIES/libbz_intermediates/bzlib.o
cp -fp /home/brandonabandon/sn/out/host/linux-x86/obj/EXECUTABLES/acp_intermediates/acp /home/brandonabandon/sn/out/host/linux-x86/bin/acp
cp: cannot stat `/home/brandonabandon/sn/out/host/linux-x86/obj/EXECUTABLES/acp_intermediates/acp': No such file or directory
make: *** [/home/brandonabandon/sn/out/host/linux-x86/bin/acp] Error 1
=make -j4 otapackage showcommands.
so earlier, cp cannot stat: /brandonabandon/host/blah/blah_intermediates blah.d: no such file or directory is occuring many times. i compiled 32 bit arm toolchains for building android with gcc 4.8, and kernel compilation with 4.9. my assumption is the host toolchain needs pointed accurately. if so, i dont know how to do it. any help?
gcc=
#!/bin/bash
*PROGNAME=`basename $0`
PREFIX32=../../gcc/linux-x86/host/i686-linux-glibc2.7-4.6/bin/i686-linux
options=" ${#} "
# sentinel prefix/suffix space to simplify pattern match below
suffix_m32=${options##* -m32 } # suffix after the last -m32
len_m32=${#suffix_m32} # length of suffix after the last -m32
# Always choose 32-bit
MY_TOOL=`dirname $0`/${PREFIX32}-${PROGNAME}
*$MY_TOOL "$#"
i did a star before the required changes

How to make a string preprocessor definition from command-line in VC 2005 (C++)?

The documentation tells me that /D command-line switch can be used to do this, like so:
CL /DDEBUG TEST.C
would define a DEBUG symbol, and
CL /DDEBUG=2 TEST.C
would give it the value 2.
But what do I do if I would like to get the equivalent of a string define, such as
#define DEBUG "abc"
?
Due to the way command line is parsed in Windows, you'll have to escape the quotes.
CL /DDEBUG=\"abc\" TEST.C
This works for me in VS2013:
/D_STRING="\"abc\""
then it is equivalent to
#define _STRING "abc"
Note, if you do
/D_STRING="abc"
It will be equivalent to
#define _STRING abc
Have you tried
CL /DDEBUG=abc TEST.C
or
CL /DDEBUG="abc" TEST.C
Thanks Glen, the second one could work on the command line, but the coworker I've asked this for eventually used this in the project definition (needing to escape the double-quotes and replace = with #):
/DDEBUG#\"abc\"
I don't have VC to test this for you, however, in principle the following should work:
CL /DSTRINGIFY(X)=#X /DDEBUG=STRINGIFY(abc) TEST.C
Update:
As highlighted by Kuber-Ober, VC doesn't seem to do the right thing here. Testing with a simple example, it generates:
const char * s = STRINGIFY(abc);
It may work with other compilers, for example the following g++ command line works:
g++ -D'STRINGIFY(X)=#X' -D'DEBUG=STRINGIFY(abc)' t.cc -E
# 1 "t.cc"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "t.cc"
const char * s = "abc";