flens lapack: GNU GCC Version 4.7 or higher required! my mac has - c++

I was trying a tutorial (http://apfel.mathematik.uni-ulm.de/~lehn/FLENS/flens/examples/lapack-geqp3.html) from FLENS-LAPACK.
I have download the src code from the website (https://github.com/michael-lehn/FLENS).
when I try the instruction from the tutorial
g++ -std=c++11 -Wall -I../.. -o lapack-geqp3 lapack-geqp3.cc
I had error from the console:
In file included from lapack-geqp3.cc:2:0:
../../flens/flens.cxx:45:6: error: static assertion failed:
GNU GCC Version 4.7 or higher required! static_assert(__GNUG__>=4 && __GNUC_MINOR__>=7,
I checked the gcc version of my mac
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-apple-darwin14.0.0/5.0.0/lto-wrapper Target: x86_64-apple-darwin14.0.0
Configured with: ../gcc-5-20141005/configure --enable-languages=c++,fortran Thread model: posix
gcc version 5.0.0 20141005 (experimental) (GCC)
It shows that my mac has gcc 5.0.0.
Can anyone tell me what's wrong with the gcc on my mac??
Thanks a lot!!

Noting is wrong with your GCC, the static_assert is wrong.
static_assert(__GNUG__>=4 && __GNUC_MINOR__>=7, ...)
This checks that GCC is both version 4.x or newer, but also minor version 7 or newer. This assertion will only pass on 4.7, 4.8, 4.9, 5.7, 5.8, ... etc.
If the assertion is changed like so:
static_assert(__GNUG__==4 && __GNUC_MINOR__>=7 || __GNUG__>4, ...)
Then it should pass for GCC 5 (assuming it defines __GNUG__ as 5; I have no way of checking at the moment.)
Edit: I've submitted a patch to fix this issue, which has already been accepted and merged. If you pull the latest HEAD, your issue should be fixed.

Related

How do I make sure that my default C/C++ compiler is GCC

I'm trying to install Riak from source on macOS (https://docs.riak.com/riak/kv/2.2.3/setup/installing/mac-osx.1.html#installing-from-source).
There is a note:
Riak will not compile with Clang. Please make sure that your default
C/C++ compiler is GCC
How do I find out which compiler is the default and how to change it?
macOS Catalina (10.15.4), which command prints:
$ which clang
/usr/bin/clang
$ which gcc
/usr/bin/gcc
On macOS Catalina (and prior versions, and most likely subsequent versions too), there are two aspects to the problem and some suggested solutions.
What is the name of the compiler used by make by default?
$ mkdir junk
$ cd junk
$ > x.cpp
$ > y.c
$ make x y
c++ x.cpp -o x
cc y.c -o y
$ cd ..
$ rm -fr junk
This shows that the names used by make are cc and c++. Those are not obviously clang or clang++, but neither are they obviously gcc and g++.
$ which cc c++
/usr/bin/cc
/usr/bin/c++
$
Which compiler is it really?
Which compiler really lives behind the names cc, c++, gcc, g++, clang, and clang++? We can check which compiler these really are by getting them to identify their version:
$ for compiler in cc c++ gcc g++ clang clang++
> do
> which $compiler
> $compiler --version
> done
/usr/bin/cc
Apple clang version 11.0.0 (clang-1100.0.33.17)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
/usr/bin/c++
Apple clang version 11.0.0 (clang-1100.0.33.17)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
/usr/bin/gcc
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple clang version 11.0.0 (clang-1100.0.33.17)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
/usr/bin/g++
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple clang version 11.0.0 (clang-1100.0.33.17)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
/usr/bin/clang
Apple clang version 11.0.0 (clang-1100.0.33.17)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
/usr/bin/clang++
Apple clang version 11.0.0 (clang-1100.0.33.17)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
$
As you can see, the versions installed in /usr/bin are all the same compiler, and that compiler is clang or clang++.
This was run on a machine with macOS Mojave 10.14.6 and XCode 11.3.1. The latest version of XCode — 11.4.1 — is only available on Catalina. However, the general conclusion is the same — all the C and C++ compilers are really clang and clang++ in disguise.
How do you get GNU GCC onto your machine?
How do you get a real GNU GCC — a real GCC, not clang in disguise — onto your machine?
Use Brew to install GCC (I've not checked which version of GCC is current).
Or use MacPorts (again, I've not checked which version of GCC is current).
If you're adventuresome, do it yourself (but I've not yet succeeded at building GCC 9.3.0 on Catalina; I have a GCC 9.2.0 built on macOS Mojave 10.14.x that works OK on Catalina though — with one environment variable needed to locate the headers).
Maybe Fink — it lists GCC 8.4 as being made available in 2020; I don't know about newer versions.
Be aware that Apple has taken to hiding the system header files miles out of the way (not in /usr/include — and you can't modify that part of the file system to add a symlink to where they've hidden them):
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
(You mean you couldn't guess that? Me neither!)
How do you change the default compiler?
Once you have GCC installed somewhere appropriate, you need to ensure you use the 'real' GCC and not the 'fake' in /usr/bin. You do that in part by ensuring that the bin directory for the 'real' GCC occurs on your PATH before /usr/bin. I have GCC 9.3.0 installed under /opt/gcc/v9.3.0, so /opt/gcc/v9.3.0/bin appears on my PATH long before /usr/bin does.
You also need to ensure that the configuration for riak (the software you're installing) uses the correct compilers. If there's a ./configure script, run it with the correct path specified for the compilers. For example, I might use:
./configure CC=/opt/gcc/v9.3.0/bin/gcc CXX=/opt/gcc/v9.3.0/bin/g++
You can also set these values as environment variables.
If it uses cmake or some other configuration package, you'll need to consult the installation instructions. That's usually README or sometimes INSTALL.
See also (increasingly older posts):
Can't compile a C program on a Mac after upgrade to Catalina
Can't compile a C program on a Mac after upgrade to Mojave
Install GNU GCC on a Mac

Compile with c++17 mac

I can't compile with -std=c++17, I got :
error: invalid value 'c++17' in '-std=c++17'
However I update Xcode and clang.
My Clang version is:
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 9.0.0 (clang-900.0.39.2)
Target: x86_64-apple-darwin16.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin`
And I load the newest header like optional, I have to do
#include <experimental/optional>
instead of
#include <optional>
Xcode brings its own complete toolchain, including headers and the actual compiler.
Apple LLVM version 9.0.0 (clang-900.0.39.2) (which ships with Xcode 9.2) does not support the usage of the flag -std=c++17 since its too old. The optional header is only included under the folder experimental/. Which is why you need to #include <experimental/optional>
In order to compile your program with c++17 support using the compiler which comes with Xcode 9.2 you need to use the -std=c++1z flag.
Xcode 9.3 will be shipped with Apple LLVM version 9.1.0 (clang-902.0.30) which has support for the -std=c++17 flag. However the optional header is as of today still under the experimental/ subdirectory. This might change during the betas.
Here is what I get with this tests:
#include <experimental/optional>
int main(int, char* []) {
return 0;
}
g++ -std=c++17 -o test test.cpp
error: invalid value 'c++17' in '-std=c++17'
g++ -std=c++1z -o test test.cpp
Did you try the c++1z argument?
Also of note my test compiles without the -std=c++1z argument provided.
I think I'm on a newer version of OSX than you:
Target: x86_64-apple-darwin17.4.0
You should use -std=c++1z as flag.
libc++ with c++17 support since macos 15
-std=c++1z also works on Apple LLVM version 8.1.0 (clang-802.0.42)

How to use the available C++17 flags from Xcode in Terminal

My Xcode 9.2 has the option to compile C++ using: -std=c++17 or -std=gnu++17.
My C++ code that has some C++17 features compiles successfully.
However, if I try to compile the same code in my Terminal using the same flags, I get the following errors:
clang++ -std=c++17 test.cpp -o test
error: invalid value 'c++17' in '-std=c++17'
and
clang++ -std=gnu++17 test.cpp -o test
error: invalid value 'gnu++17' in '-std=gnu++17'
My OSX version is 10.13.3 and my Clang++ version is:
Apple LLVM version 9.0.0 (clang-900.0.39.2)
Target: x86_64-apple-darwin17.4.0
I thought that Terminal would use the same compiler from Xcode. That may be the case, but I can't use the same options. At least I couldn't.
I tried using -std=C++1z, but it didn't compile my code because it doesn't understand some new features from C++17.
So my question is: Is there a way to use -std=c++17 or -std=gnu++17 that are currently available in my Xcode 9.2, in my Terminal app?
This questions is not the same as the others available at stackoverflow because all the answers I found the -std=c++17options was not available in Xcode. Now we have this options, but I can't figure out how to use it in Terminal.
The compiler Apple currently ships with Xcode 9.2 (clang-900.0.39.2) does not support the -std=c++17 flag.
Xcode uses the -std=c++1z flag when you enable c++17 support. If you want to use -std=c++17 you need to manually install clang. You could do that using brew install llvm (assuming you have homebrew installed).
You can compile your program with
/usr/local/Cellar/llvm/5.0.0/bin/clang++ -std=c++17 test.cpp -o test
You change the symlinks in usr/bin/clang++ to point at the new destination if you don't want to use the full path to the compiler.
The compiler which is shipped with Xcode 9.3 will be
Apple LLVM version 9.1.0 (clang-902.0.30)
This can handle the -std=c++17 flag.

os x LLVM supports c++11/14, why the include directory is still gcc 4.2.1?

On my new macbook pro, after install xcode, I found:
Both gcc and clang are linking to LLVM 7.3. I guess gcc is just an alias of clang here, right?
As long as gcc supports -std=c++11 and -std=c++14 parameter, why the /usr/include/c++ only has a directory named "4.1.2"? I know gcc 4.1.2 is quite an old version,

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