c++: error: unrecognized command line option ‘-std=c++17’ - c++

[ 25%] Building CXX object CMakeFiles/linreg-dlib.dir/linreg_dlib.cc.o
/usr/bin/c++ -I/home/jeong/다운로드/dlib-master -I"/home/jeong/바탕화면/9781789955330_Code/Chapter01/dlib_samples/path to dlib install dir/include" -std=c++17 -msse3 -fopenmp -Wall -Wextra -o CMakeFiles/linreg-dlib.dir/linreg_dlib.cc.o -c /home/jeong/바탕화면/9781789955330_Code/Chapter01/dlib_samples/linreg_dlib.cc
c++: error: unrecognized command line option ‘-std=c++17’
make[2]: *** [CMakeFiles/linreg-dlib.dir/linreg_dlib.cc.o] error 1
make[2]: Leaving directory `/home/jeong/바탕화면/9781789955330_Code/Chapter01/dlib_samples'
make[1]: *** [CMakeFiles/linreg-dlib.dir/all] error 2
make[1]: Leaving directory `/home/jeong/바탕화면/9781789955330_Code/Chapter01/dlib_samples'
make: *** [all] error 2
c++: error: unrecognized command line option ‘-std=c++17’
I am running the practice code using the dlib library.
It runs until'cmake', but the above error appears during'make' process. Need to update gcc?
The gcc version is shown below.
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39)
How to do it if you need to update the version
I wonder.

The GCC releases page (https://www.gnu.org/software/gcc/releases.html) says that gcc 4.8.5 was released on June 23, 2015.
The GCC developers are really good, but shipping C++17 support two years before C++17 was completed is beyond good.
That compiler may support -std=c++1z for some C++17 features, though.

As others have mentioned your compiler is too old for C++17.
It sounds like you are on either RHEL 7 or CentOS 7. Those OSes support installation of "Developer Toolsets" with newer versions of the compiler and toolchain (in addition to the standard system compiler).
This might be an option for you.
For RHEL 7 see: https://access.redhat.com/documentation/en-us/red_hat_developer_toolset/10/
For CentOS see: https://www.softwarecollections.org/en/scls/rhscl/devtoolset-8/

Related

Install g++ from source in Fedora 26

I am trying to install a c++ compiler on a IBM Power7 with Fedora 26.
In /usr/bin it is installed gcc [(GCC) 7.2.1 20170915 (Red Hat 7.2.1-2)] but it has not the c++ compiler (I tried gcc -lstdc++ but the result is: `
/usr/bin/ld: cannot find -lstdc++
I do not have sudo rights so I have to install everything from source.
I was able to install:
Zlib
Perl
Curl
Git
GNU M4
GMP
MPFR
MPC
EXPAT
APR and APR-UTIL
ISL
but when I try to install locally gcc, after a successfull configure, when I try make I got this error:
configure: error: in `/home/aantonietti/gcc/host-powerpc64-unknown-linux-gnu/gcc':
configure: error: C++ preprocessor "/lib/cpp" fails sanity check
See `config.log' for more details.
make[2]: *** [Makefile:4333: configure-stage1-gcc] Error 1
make[2]: Leaving directory '/home/aantonietti/gcc'
make[1]: *** [Makefile:23745: stage1-bubble] Error 2
make[1]: Leaving directory '/home/aantonietti/gcc'
make: *** [Makefile:945: all] Error 2
I also tried to install clang++ but it needs tons of other dependecies.
Do you have any hint on how to install just the gcc-c++ compiler?
Why don't you run dnf install gcc-c++? It will install the C++ system compiler bring in linking support for libstdc++ as well.

Update g++ reached from NetBeans under OS X

I am trying to build a C++ project in NetBeans 8.2 under OS X with the C++14 standard. However, I am always getting the error while trying to build:
g++ -c -g -std=c++14 -MMD -MP -MF "build/Debug/GNU-MacOSX/test.o.d" -o build/Debug/GNU-MacOSX/test.o test.cpp
error: invalid value 'c++14' in '-std=c++14'
make[2]: *** [build/Debug/GNU-MacOSX/test.o] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 570ms)
Nevertheless, I can run the same command from the terminal without any problems. My version of g++ is 7.0.0, and so the C++14 standard is fully supported.
Therefore, it seems like NetBeans tries to run some older version of g++, which was probably supplied with the system but now is replaced with a new one. To this I have two questions:
How can it be possible that default versions in the terminal and NetBeans are different?
How can I configure NetBeans to work with the terminal default version?
EDIT:
In the terminal which g++ yields /opt/local/bin/g++. The same is in the field Preferences -> C/C++ -> C++ compiler. Adding the --version argument in NetBeans yields Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn), which is definitely different from the console version. So, I still do not understand: why calling g++ under the same path resolves to different versions in NetBeans and the terminal?

c++: error: unrecognized command line option ‘-std=gnu++14’

I try to build the fblualib. However, when running build.sh I get the following error:
-- Found Folly: /usr/local/include
-- Found Torch7 in /home/dmus/torch/install
-- Found Folly: /usr/local/include
-- Configuring done
-- Generating done
-- Build files have been written to: /home/dmus/fblualib/fblualib/build
[ 25%] Building CXX object CMakeFiles/fblualib.dir/LuaUtils.cpp.o
c++: error: unrecognized command line option ‘-std=gnu++14’
make[2]: *** [CMakeFiles/fblualib.dir/LuaUtils.cpp.o] Error 1
make[1]: *** [CMakeFiles/fblualib.dir/all] Error 2
make: *** [all] Error 2
g++ --version outputs g++ (Ubuntu 4.8.4-2ubuntu1~14.04.1) 4.8.4. I see related questions, however I do not see how to fix this.
You need to upgrade your g++ (At least to version 4.9.*).
Once upgrade is done, try compiling using g++ -std=c++14 file.cpp or g++ -std=c++1y file.cpp.

clang: warning: no such sysroot directory: '-mmacosx-version-min=10.5' on compiling LLVM (3.9.0)

I am compiling LLVM (3.9.0) using CMake (3.6.2) on my Mac (OsX) using GCC, but somehow I am getting the following error with following GCC configuration
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.3.0 (clang-703.0.31)
Target: x86_64-apple-darwin15.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
[50%] Building C object projects/compiler-rt/lib/builtins/CMakeFiles/clang_rt.eprintf.dir/eprintf.c.o
clang: warning: no such sysroot directory: '-mmacosx-version-min=10.5'
/Users/Ritzy/llvm_src/llvm-3.9.0.src/projects/compiler-rt/lib/builtins/eprintf.c:14:10: fatal error: 'stdio.h' file not found
#include <stdio.h>
^
1 error generated.
make[2]: *** [projects/compiler-rt/lib/builtins/CMakeFiles/clang_rt.eprintf.dir/eprintf.c.o] Error 1
make[1]: *** [projects/compiler-rt/lib/builtins/CMakeFiles/clang_rt.eprintf.dir/all] Error 2
make: *** [all] Error 2
I am using following CMake command:
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR ..
cmake --build .
I spent hours figuring out what was wrong. Even tried to using gcc6 and clang but in vain.
Here's an example of what the command line flags supplied to a MacOS/X clang invocation might look like:
-pipe -stdlib=libc++ -std=c++11 -stdlib=libc++ -O2 -std=gnu++11 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -mmacosx-version-min=10.7 -Wall -W -fPIC $(DEFINES)
Note in particular this part:
-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -mmacosx-version-min=10.7
-isysroot tells the compiler where to look for header files, and then the next argument -mmacosx-version-min=10.7 tells it what minimum version of MacOS/X to maintain backwards compatibility with.
In your case, your CMake invocation probably isn't specifying a value for the -isysroot argument, instead it probably has something like this:
-isysroot -mmacosx-version-min=10.5
... where the path that was intended to be supplied after the -isysroot flag has been left blank (i.e. an empty string) for some reason, and that is why "-mmacosx-version-min=10.5" is being interpreted as a path to look for header files in (which of course will not work).
As to why the path argument was left blank, that is something you'll have to investigate on your own.

luarocks 'gcc-plugin.h' build error

I am trying to use torch together with the hdf5 package. I am trying to install it via luarocks install hdf5 but during the build phase I get an error regarding the gcc-plugin header. (gcc relies on clang backend). The complete error message is:
luarocks install --local hdf5
Installing https://luarocks.org/hdf5-2.0.0-1.src.rock...
Using https://luarocks.org/hdf5-2.0.0-1.src.rock... switching to 'build' mode
Warning: variable CFLAGS was not passed in build_variables
gcclua-config.h:1:10: fatal error: 'gcc-plugin.h' file not found
#include "gcc-plugin.h"
^
1 error generated.
env MACOSX_DEPLOYMENT_TARGET=10.8 gcc -c -o gcclua.o -Iplugin/include -fPIC -O2 -Wall -Wformat-security -I/usr/local/Cellar/lua/5.2.4_3/include gcclua.c
gcclua.c:7:10: fatal error: 'gcc-plugin.h' file not found
#include "gcc-plugin.h"
^
1 error generated.
make[2]: *** [gcclua.o] Error 1
make[1]: *** [gcc] Error 2
make: *** [gcc-lua] Error 2
Just to give more information, I am relying on
gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
xcrun: error: couldn't stat toolchain: '/Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.11.xctoolchain' (errno=No such file or directory)
Apple LLVM version 7.3.0 (clang-703.0.29)
Target: x86_64-apple-darwin15.0.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
Does anybody has maybe a hint how to fix this issue?
Every help is greatly appreciated!!!
In addition to gcc, you need the headers, which on Linux you can get with sudo apt-get install gcc-4.8-plugin-dev. If you're on a different OS or version of gcc, just substitute the appropriate package manager / gcc version number.
gcc-plugin.h is a part of GCC, so I think you'll really need to install gcc to get that. Clang provides a gcc-compatible front-end script but that merely presents a command-line driver with compatible flags.
You should be able to install GCC using Homebrew: https://apple.stackexchange.com/a/86588
I bet you tried to work on a CS287-16 class :). I have contacted the developer of this library who wasn't that easy to do something to solve the problem. Apparently he has no friends who have a Mac PC... As a workaround I could suggest you to use a Docker container with Linux in it to run Lua scripts. That's what I have ended up with...
Here's the Docker image I was talking about: https://github.com/aoboturov/cs287-16-lua. You could build it yourself and the just run as a Docker container :)