Compiling C++ files when including cmath in header - c++

I have recently installed gcc from http://hpc.sourceforge.net/ and while everything else works fine whenever I try to include cmath in the header it is showing the following error:
/usr/local/lib/gcc/x86_64-apple-darwin13.4.0/5.0.0/include-fixed/math.h:273:5: internal compiler error: Illegal instruction: 4
return __inline_isfinitef(__x) && __builtin_fabsf(__x) >= __FLT_MIN__;
^
/usr/local/lib/gcc/x86_64-apple-darwin13.4.0/5.0.0/include-fixed/math.h:273:5: internal compiler error: Abort trap: 6
g++: internal compiler error: Abort trap: 6 (program cc1plus)
Abort trap: 6
I'm using OSX Yosemite and on typing gcc -v it shows the following:
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-apple-darwin13.4.0/5.0.0/lto-wrapper
Target: x86_64-apple-darwin13.4.0
Configured with: ../gcc-5-20140928/configure --enable-languages=c++,fortran
Thread model: posix
gcc version 5.0.0 20140928 (experimental) (GCC)
Thanks in advance for your time.

This can happen when the GMP library was compiled for CPU which provides instructions not available on the runtime CPU, see gmp CPU identification

Related

clang-800.0.42.1 and open mp

I'm running max os x 10.11.6 and want to include openmp in my programs, meaning compile with -fopenmp which is giving me the error:
clang: error: unsupported option '-fopenmp'
clan --version is giving me:
Apple LLVM version 8.0.0 (clang-800.0.42.1)
Target: x86_64-apple-darwin15.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
According to
https://clang-omp.github.io/
clang supports openmp from version 3.7 onwards.
My first question is how does "clang-800.0.42.1" relate to "clang 3.7", so do I actually have open mp support?
My second question is, according to this simple example:
http://blog.llvm.org/2015/05/openmp-support_22.html
I have to tell clang where the omp header files and libs are located as well as add the libs to DYLD_LIBRARY_PATH. But what are the files and libs exactly called and where can I find them? I'm running default xcode without any homebrew/special compiler stuff installed.
Thx for the help!

gfortran doesn't work after upgrading to El Capitan

I tried upgrading to El-Capitan and Xcode 7.0 and now gfortran doesn't work. Everytime I run gfortran, I get errors which google search doesn't seem to resolve so I'm asking stack overflow:
I'm trying to compile a minimal example program:
program hello
print *, "Hello World"
end program hello
When I run gfortran test.f
gfortran: warning: couldn’t understand kern.osversion ‘15.0.0
ld: library not found for -lgcc_s.10.4
collect2: error: ld returned 1 exit status
I'm not worried about the warning but the error of the ld is what's really bothering me. There's libgcc_s.10.4.tbd in the /usr/lib folder but it seems not be used by gfortran.
Can anyone help me resolve this as I would like to use gfortran for compiling some libraries?
MORE info: running gfortran -v outputs
gfortran: warning: couldn’t understand kern.osversion ‘15.0.0
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-apple-darwin12.2.0/4.8.0/lto-wrapper
Target: x86_64-apple-darwin12.2.0
Configured with: ../gcc-4.8-20120930/configure --enable languages=c++,fortran
Thread model: posix
gcc version 4.8.0 20120930 (experimental) (GCC)
The version of gfortran you have (4.8 installed into /usr/local) is not a version of GCC that apple would have distributed with Xcode (afaik they never made it to a version of GCC that new before switching to llvm, which has no Fortran front-end. The version of gcc distributed with Xcode 7 on el capitan identifies itself as:
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.0.0 (clang-700.0.72)
Target: x86_64-apple-darwin15.0.0
Thread model: posix
Your version came from somewhere else and is old enough to not know the x86_64-apple-darwin15.0.0 target. You'll need to update that compiler to get a working gfortran. Both macports and homebrew provide easy installations of various versions of gcc/gfortran on OS X el capitan, and I'd recommend using one of those to install gcc. Alternatively you can track down whatever you used to install gcc 4.8 before and see if they provide an update for el capitan.

How to emit optimisation reports using Apple clang 3.5?

According to the documentation, clang supports options to emit optimisation reports:
When the pass makes a transformation (-Rpass).
When the pass fails to make a transformation (-Rpass-missed).
When the pass determines whether or not to make a transformation (-Rpass-analysis).
They provide the following example command line:
$ clang -O2 -Rpass=inline code.cc -o code
When I try this, I get an error:
$ clang src/test/tests.cpp -Rpass=inline
clang: error: unknown argument: '-Rpass=inline'
scons: *** [build/test/tests.o] Error 1
scons: building terminated because of errors.
My clang version is:
$ clang --version
Apple LLVM version 6.0 (clang-600.0.54) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin14.0.0
Thread model: posix
Is this option not available on Mac OS? Is the documentation erroneous? Or am I doing it wrong? If so, how to do it right?
Works for Debian clang-3.5.0-6, so this is probably Apple clang restriction.
% clang++ -O2 -Rpass=inline foo.cpp
foo.cpp:11:2: remark: _ZN1CC2Ev inlined into main [-Rpass=inline]
P* p = new C();
^
% clang --version
Debian clang version 3.5.0-6 (tags/RELEASE_350/final) (based on LLVM 3.5.0)
Target: i386-pc-linux-gnu
Thread model: posix

The command line clang/clang++ doesn't work on MacBook Air 2012 Mid with OS X 10.8.5

Originally, I used clang++ with -std=c++11 compile my C++11 code, everything was OK. Recently, I updated the Xcode in AppStore, I compiled the SAME program in command line again, it doesn't work anymore, it shows errors like below:
/usr/include/c++/4.2.1/bits/stl_construct.h:81:38: error: no matching
constructor for initialization of
'std::basic_string'
::new(static_cast(__p)) T1(_value);
It seems the clang++ is using gcc's header files, apparently, gcc's version is very old. However, if I compile the same program by using Xcode, everything is fine.
It seems, at command line , the clang++ can't find the correct header files anymore.
More information, running command clang++ --version, following output:
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin12.5.0 Thread model: posix
which clang++
/usr/bin/clang++
RESOLVED with option -stdlib=libc++

clang's support of C++ 11 lambda

I have this C++ 11 code that uses lambda, this is an example.
#include <iostream>
using namespace std;
int main()
{
auto func = [] () { cout << "Hello world"; };
func(); // now call the function
}
When I compiled this code with clang 3.1 (Apple clang version 3.1 (tags/Apple/clang-318.0.54) (based on LLVM 3.1svn)), I got this error
lambda.cpp:7:17: error: expected expression
auto func = [] () { cout << "Hello world"; };
What might be wrong? In this site, lambda seems to be supported with clang 3.1.
ADDED
With -std=gnu++11 or c++11 option, I got these error messages.
0. Program arguments: /usr/bin/clang -cc1 -triple x86_64-apple-macosx10.7.4 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name lambda.cpp -pic-level 1 -mdisable-fp-elim -relaxed-aliasing -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 128.2 -resource-dir /usr/bin/../lib/clang/3.1 -fmodule-cache-path /var/folders/ng/h2hkycqd2q5g2hz42c47bt4w0000gn/T/clang-module-cache -std=gnu++11 -fdeprecated-macro -fdebug-compilation-dir /Users/smcho/Desktop/C++test -ferror-limit 19 -fmessage-length 173 -stack-protector 1 -fblocks -fobjc-runtime-has-arc -fobjc-runtime-has-weak -fobjc-dispatch-method=mixed -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/ng/h2hkycqd2q5g2hz42c47bt4w0000gn/T/lambda-XvZzHg.o -x c++ lambda.cpp
1. lambda.cpp:7:49: current parser token ';'
2. lambda.cpp:6:1: parsing function body 'main'
3. lambda.cpp:6:1: in compound statement ('{}')
clang: error: unable to execute command: Segmentation fault: 11
clang: error: clang frontend command failed due to signal 2 (use -v to see invocation)
clang: note: diagnostic msg: Please submit a bug report to http://developer.apple.com/bugreporter/ and include command line arguments and all diagnostic information.
clang: note: diagnostic msg: Preprocessed source(s) and associated run script(s) are located at:
clang: note: diagnostic msg: /var/folders/ng/h2hkycqd2q5g2hz42c47bt4w0000gn/T/lambda-roTwCZ.ii
clang: note: diagnostic msg: /var/folders/ng/h2hkycqd2q5g2hz42c47bt4w0000gn/T/lambda-roTwCZ.sh
This is because clang++ by default compiles your code using ISO C++ 1998 standard (including the defects addressed in the ISO C++ 2003 standard) except for 'export' (which has been removed in C++11)
Lambdas are part of Clang's C++11 Language Extension, therefore you need to compile your code with -std=c++11 or -std=gnu++11
Also see: Clang 3.1 and C++11 support status and Activating C++11 support in Clang
EDIT: I think you are trying to compile your program with the C compiler (clang) rather than C++ compiler (clang++) or your installation of Clang doesn't link to libc or libstdc++. Try to link against each library to see which one works for you, it is possible that libc might not be installed on your system.
Try to compile your program with C++11 mode using the clang++ executable (the C++ compiler) and link it either with Clang C++ Standard Library or the GNU Standard C++ Library
1)
# Uses Clang C++ Library and enables C++11 mode
clang++ -stdlib=libc++ -std=c++11 [input]
2)
# Uses GNU Standard C++ Library and enables C++11 mode
clang++ -stdlib=libstdc++ -std=c++11 [input]
Another possible problem might be that you haven't compiled Clang with the right options to enable C++11 language extensions, try and check the documentation for correct flags to use when you configure the compilation process for Clang.
The Xcode is updated using AppStore, but it still crashes on my Mac (Lion 10.7.5)
I could download the macport to compile the example successfully.
sudo port install clang-3.1
clang++-mp-3.1 -std=c++11 lambda.cpp
Responding to the newly edited post:
I investigated this issue a bit, and it's a bug that was corrected in release versions of clang 3.1. I'm currently using:
Debian clang version 3.1-3eudoxos1 (branches/release_31) (based on LLVM 3.1)
However when I tested with clang 3.0-6ubuntu3 I get a similar error to the one you posted.
Because your version is marked from SVN I assume that your issue is that it's from the prerelease versions of 3.1 and lambda support hadn't been fully implemented yet.
I can confirm that lambdas do work in clang because I'm working on a project that uses them and we target both clang and gcc. There are a few compiler boogs that crop up from time to time; however, nothing as simple as your given example, of course.
So, my recommendation is to update your version of clang.
I needed to install command line tools as is this post explains - Does Xcode 4.4 come with subversion?