Apparently, CERN's "Root" software is compatible (as of version 6.12) with C++17. However, I have been completely unable to get this to work with the newest version (6.20) and all previous questions I found on this topic are from a few years ago.
Does anyone with Root experience know if there is a particular compiler option to get it to work with C++17?
Examples of errors I get when trying to compile a trivial "Hello world" program:
The following is (I think) due to the "TFile.h" header implicitly loading "TString.h":
/usr/local/bin/root_v6.20.02/include/ROOT/RStringView.hxx:32:84: error: conflicting declaration of template ‘template<class _CharT, class _Traits> using basic_string_view = std::experimental::__ROOT::basic_string_view<_CharT, _Traits>
An example of another (more mysterious, to me at least) error is:
/usr/include/c++/7/ext/concurrence.h:53:16: error: ‘_Lock_policy’ does not name a type
static const _Lock_policy __default_lock_policy =
^~~~~~~~~~~~
In file included from /usr/include/c++/7/iostream:38:0,
from test.cpp:1:
/usr/include/c++/7/ext/concurrence.h: In function ‘void std::__throw_concurrence_lock_error()’:
/usr/include/c++/7/ext/concurrence.h:102:5: error: ‘__concurrence_lock_error’ was not declared in this scope
{ _GLIBCXX_THROW_OR_ABORT(__concurrence_lock_error()); }
^
/usr/include/c++/7/ext/concurrence.h:102:5: note: suggested alternative:
In file included from /usr/include/c++/7/memory:74:0,
from /usr/local/bin/root_v6.20.02/include/ROOT/TypeTraits.hxx:15,
from /usr/local/bin/root_v6.20.02/include/TString.h:29,
from /usr/local/bin/root_v6.20.02/include/TNamed.h:26,
from /usr/local/bin/root_v6.20.02/include/TKey.h:15,
from /usr/local/bin/root_v6.20.02/include/TBasket.h:28,
from /usr/local/bin/root_v6.20.02/include/ROOT/TIOFeatures.hxx:14,
from /usr/local/bin/root_v6.20.02/include/TTree.h:30,
from /usr/local/bin/root_v6.20.02/include/TNtuple.h:24,
from test.cpp:2:
/usr/include/c++/7/ext/concurrence.h:67:9: note: ‘__gnu_cxx::__concurrence_lock_error’
class __concurrence_lock_error : public std::exception
I am using the latest version of g++ and Root, on Linux, and have the following options in my Makefile:
CXX = g++
CXXFLAGS = -march=native `root-config --cflags --libs` -std=c++17
LDFLAGS = `root-config --cflags --libs`
Any comments about a possible workaround would be appreciated, or perhaps there is some additional option I need to add in the Makefile? It would also be helpful to know if it is advisable to stick to C++11/14 when using Root libraries.
You can use root only with the c++ standard with which your root version has been compiled. This is a known inconvenience and I believe the developers would be happy if/when they get this sorted out. The build configuration root-config --cflags should set the appropriate c++ standard. This might very well be c++17 (it is for me)
pseyfert#robusta:~ > root-config --cflags
-pthread -std=c++17 -m64 -fdiagnostics-color -march=native -Wextra -Wall -Wshadow -I/home/pseyfert/coding/root-install/include
If you compile root from source, then CMAKE_CXX_STANDARD=17 or cxx17=ON (doc) are the build options you want to set to compile root with c++17 and use c++17 in all downstream projects.
If you use a binary installation of root that switch needs to be done by whoever provides the build.
Related
I'm trying to code the BST ADT, and the specification we were given requires use of 'auto' that is only included in C++14. I'm trying to compile, but I keep getting errors that 'auto' is only included in C++14, so I'm just wondering if there's a different way to compile the code so that it includes C++14? In every previous project I've done (over the last three semesters) I've been able to compile the file (say called main.cpp) just by using the code:
g++ -o main main.cpp
I've tried the following compile code
g++ -std=c++14 -o main main.cpp
but when I do that, I get like 100 errors that look like
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/string:1002:86: error: member reference base type 'std::__1::basic_string::__self_view' (aka 'int') is not a structure or union
append(const _Tp& __t) { __self_view __sv = __t; return append(__sv.data(), __sv.size()); }
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/string:1002:99: error: member reference base type 'std::__1::basic_string::__self_view' (aka 'int') is not a structure or union
append(const _Tp& __t) { __self_view __sv = __t; return append(__sv.data(), __sv.size()); }
What do these even mean?
I figured out the reasons behind the errors (turned out to be templating mistakes), but in the end compiling with g++ -std=c++14 -o main main.cpp is working. I still don't really understand any of the compilation stuff though, so if someone could explain a little bit/ provide a link I would appreciate
(this is not an answer, but too long for a comment)
Where did you get your g++ from? On most modern Mac OS installs, it is a symlink for clang++. What does g++ --version print?
Certainly you're using libc++, not libstdc++. The __1 in the type names is a giveaway, along with the path to <string>.
And the error message ('std::__1::basic_string::__self_view' (aka 'int') is weird, too. basic_string::__self_view is a string_view, not an int.
if you use Unix based operating systems such as Linux and OS X try this:
clang++ -g -std=c++1y main.cpp -o main
I am on a 64 bit CentOS 6.7 machine with g++ 4.4.7 and I am trying to compile the ACE TAO library 1.2 that was compiled with g++ 2.96.
When I try to compile using the g++ version 4.4.7 I get the following errors (more complete output here
g++ -W -Wall -Wpointer-arith -pipe -O3 -g -Wno-uninitialized -fno-implicit-templates -D_POSIX_THREADS -D_POSIX_THREAD_SAFE_FUNCTIONS -D_REENTRANT -I/home/oscarpelaoo/Downloads/ACE_wrappers -DACE_HAS_EXCEPTIONS -c -fPIC -o .shobj/URL_Addr.o URL_Addr.cpp
In file included from /home/oscarpelaoo/Downloads/ACE_wrappers/ace/ACE.h:17,
from /home/oscarpelaoo/Downloads/ACE_wrappers/ace/INET_Addr.h:17,
from URL_Addr.h:20,
from URL_Addr.cpp:3:
/home/oscarpelaoo/Downloads/ACE_wrappers/ace/OS.h:3110:27: error: new.h: No such file or directory
In file included from /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/backward/strstream:47,
from /home/oscarpelaoo/Downloads/ACE_wrappers/ace/streams.h:70,
from /home/oscarpelaoo/Downloads/ACE_wrappers/ace/OS.h:3197,
from /home/oscarpelaoo/Downloads/ACE_wrappers/ace/ACE.h:17,
from /home/oscarpelaoo/Downloads/ACE_wrappers/ace/INET_Addr.h:17,
from URL_Addr.h:20,
from URL_Addr.cpp:3:
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/backward/backward_warning.h:28:2: warning: #warning This file includes at least one deprecated or antiquated header which may be removed without further notice at a future date. Please use a non-deprecated interface with equivalent functionality instead. For a listing of replacement headers and interfaces, consult the file backward_warning.h. To disable this warning use -Wno-deprecated.
In file included from /home/oscarpelaoo/Downloads/ACE_wrappers/ace/OS_TLI.h:191,
from /home/oscarpelaoo/Downloads/ACE_wrappers/ace/OS.h:38,
from /home/oscarpelaoo/Downloads/ACE_wrappers/ace/ACE.h:17,
from /home/oscarpelaoo/Downloads/ACE_wrappers/ace/INET_Addr.h:17,
from URL_Addr.h:20,
from URL_Addr.cpp:3:
/home/oscarpelaoo/Downloads/ACE_wrappers/ace/OS_TLI.inl: In static member function ‘static int ACE_OS_TLI::t_accept(ACE_HANDLE, ACE_HANDLE, t_call*)’:
/home/oscarpelaoo/Downloads/ACE_wrappers/ace/OS_TLI.inl:12: warning: the address of ‘call’ will never be NULL
/home/oscarpelaoo/Downloads/ACE_wrappers/ace/OS_TLI.inl:13: warning: the address of ‘reshandle’ will never be NULL
/home/oscarpelaoo/Downloads/ACE_wrappers/ace/OS_TLI.inl:14: warning: the address of ‘handle’ will never be NULL
/home/oscarpelaoo/Downloads/ACE_wrappers/ace/OS_TLI.inl: In static member function ‘static char* ACE_OS_TLI::t_alloc(ACE_HANDLE, int, int)’:
After a bit of research, I found that Red Hat offers some old libstdc++ libraries for CentOS 6 here.
Is it possible to use an old version of g++ 2.96 which I don't believe has 64 bit support or can I somehow use the compatibility tools with g++ 4.4.7 to try to make something happen?
Answering my own post since I was able to install it.
After installing the relevant 32bit libraries, the -m32 flag needed to get added. Then we needed to add a -DACE_LACKS_NEW_H flag since my system does not contain the <new.h> file. After that I just needed add a forward declaration and the library compiled.
I have recently updated gcc and g++ to version 7.2. I would like to try out std::experimental::any and std::variant in particular, and I am using Qt 5.9.1 in QtCreator.
So far I have written this in the project file:
CONFIG += c++17
And I have added the correct headers in the correct places:
#include <variant>
#include <experimental/any>
Any works fine, no problems there. However, when I include the variant header file, I get this error:
/usr/include/c++/7/bits/c++17_warning.h:32: error: #error This file requires compiler and library support for the ISO C++ 2017 standard. This support must be enabled with the -std=c++17 or -std=gnu++17 compiler options.
#error This file requires compiler and library support \
^~~~~
I have tried a variety of things in the project file, here is the full list:
CONFIG += c++17
&
CONFIG += c++1z
&
QMAKE_CXXFLAGS += -std=c++17
&
QMAKE_CXXFLAGS += -std=c++1z
&
CONFIG += c++17
QMAKE_CXXFLAGS += -std=c++17
&
CONFIG += c++1z
QMAKE_CXXFLAGS += -std=c++1z
&
CONFIG += c++11
CONFIG += c++14
CONFIG += c++17
That's every stab in the dark I could think of. What am I missing? And why does experimental::any compile when variant doesn't?
I know I shouldn't use CONFIG += c++xx and QMAKE_CXXFLAGS together in this way, but I thought I'd give it a go as nothing else works. For bonus points, I'm also wondering, should I add the CONFIG calls for 14 and 11 when I already CONFIG for 17?
EDIT:
Here is the compiler output with most of my filenames scrubbed out:
18:04:10: Running steps for project AIQt...
18:04:10: Configuration unchanged, skipping qmake step.
18:04:10: Starting: "/usr/bin/make"
/home/pete/Qt/5.9.1/gcc_64/bin/qmake -o Makefile ../AIQt/AIQt.pro -spec linux-g++ CONFIG+=debug CONFIG+=qml_debug
WARNING: Failure to find: ../src/stdafx.h
WARNING: Failure to find: ../src/Csound/csd.h
g++ -c -pipe -g -Wall -W -D_REENTRANT -fPIC -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_DATAVISUALIZATION_LIB -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../AIQt -I. -I../src -I../src/AIBase -I../src/Maths -I../src/Random -isystem /usr/local/include/csound -I../../../../Qt/5.9.1/gcc_64/include -I../../../../Qt/5.9.1/gcc_64/include/QtDataVisualization -I../../../../Qt/5.9.1/gcc_64/include/QtWidgets -I../../../../Qt/5.9.1/gcc_64/include/QtGui -I../../../../Qt/5.9.1/gcc_64/include/QtCore -I. -isystem /usr/include/libdrm -I. -I../../../../Qt/5.9.1/gcc_64/mkspecs/linux-g++ -o main.o ../AIQt/main.cpp
In file included from /usr/include/c++/7/variant:35:0,
from ..###,
from ..###,
from ..###,
from ..###,
from ..###,
from ..###,
from ..###,
from ..###:
/usr/include/c++/7/bits/c++17_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2017 standard. This support must be enabled with the -std=c++17 or -std=gnu++17 compiler options.
#error This file requires compiler and library support \
^~~~~
In file included from ..###,
from ..###
from ..###,
from ..###,
from ..###,
from ..###,
from ..###:
../src/AIBase/Geno.h:70:18: error: ‘variant’ in namespace ‘std’ does not name a type
std::variant m_valueVariant;
^~~~~~~
In file included from ..###,
from ..###,
from ..###,
from ..###,
from ..###,
from ..###:
../src/AIBase/Pheno.h:22:13: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
const double getGenoValue(size_t genoIndex) const;
^~~~~
../src/AIBase/Pheno.h:24:13: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
const UserRating getRating() const;
^~~~~
In file included from ..###,
from ..###:
../AIRadioQt/GraphDialog.h:16:15: warning: declaration ‘struct ar::ai::ClusterList’ does not declare anything
class ar::ai::ClusterList;
^~~~~~~~~~~
make: *** [main.o] Error 1
18:04:13: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project AIQt (kit: Qt 5.9.1 GCC 64bit)
The kit Qt 5.9.1 GCC 64bit has configuration issues which might be the root cause for this problem.
When executing step "Make"
18:04:13: Elapsed time: 00:03.
ANSWER:
As mentioned by nwp, I just had to clean it and rebuild.
Another poster also commented that CONFIG += c++17 doesn't appear to be supported yet, so it is necessary to use QMAKE_CXXFLAGS += -std=c++17. He quickly deleted his comment though, so I am unable to thank him personally for going to the effort of checking the docs for me.
CONFIG += c++17 can be used with Qt 5.12 and later.
For Qt 5.11 and earlier, it is not a recognized QMake flag and you have to get your hands a bit dirty.
Adding QMAKE_CXXFLAGS += -std=c++17 does the job for GCC & Clang; for MSVC you will probably need to specify /std:c++17 or /std:c++latest.
Edit 3/2019: You can use CONFIG += c++17 since Qt 5.12.
The actual flag is c++1z, not c++17. In short, to get C++17 support, you don't need to modify QMAKE_CXXFLAGS and can instead simply use CONFIG += c++1z.
Discussion on the reason why can be found in this bug report, but it pretty much amounts to "we implemented it as c++1z before C++17 was standardized, and now we won't bother aliasing it."
Note: I realize you just needed a clean and rebuild. I'm answering the underlying question of "what flags do I need to use to enable C++17 support?"
By Example C++17 C++20 Builds with Qt5 version 5.15.3 (and above) on Linux (or similar on Windows)
Summary:
Inside CMakeLists.txt file for an application written in C++17 and using Qt
cmake_minimum_required(VERSION 3.16.0)
project(helloworld VERSION 1.0.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
A qt project configuration eg mygame.pro may have c++1z for C++17 or c++2a for C++20 or c++11 for older projects:
CONFIG += c++1z
On the command line of configure eg a C++20 project config, always use a shadow build:
../configure -c++std c++2a
cmake --build .. --parallel
Windows or Linux compiler command arguments examples with or without qt; at time of writing C++20 is c++2a and C++17 is c++1z others to follow.
$ g++ -std=c++2a hello_linux_is_the_worlds_device_future.cpp
c:\hello> cl /std=c++1z /EHsc hello_windows_is_in_decline.cpp
On windows notice the forward /slash.
More Detail:
I have found that building a new C++ project or even building ALL of qt5 open source thus creating my own qt release (which is tough) is possible by C++17 or C++20 (Qt6 requires at least C++17). I cloned and then checked out version qt5 5.15 i.e. ALL of qt5 open source and built it using C++20 - the build takes 23GB ... you don't need to do all that.
Note the config examples below, ... 4 hours of build on a fast PC are super fussy and I managed eventually. Anyway the point is that Qt5.15 was happy to build itself with the C++17 or C++20 settings (in my case using gcc g++-8 or g++-9) by example:
Just take a look at this cmake Get Started (qt6 C++17 example) but 20 works just as well)
Qt5 open source code total build of qt5.15.3 with C++20 configure example:-
mkdir qt5-build
cd qt5-build
../configure -release -opensource -nomake examples -nomake tests
-skip qtdocgallery -c++std c++2a -confirm-license -opengl desktop
-platform linux-g++-64 # put this all on one-line please.
cmake --build .. --parallel
OR use make -j4 as I did.
Considerable care was taken to write this for my own notes which I share, I am happy to make corrections myself and suggestions are welcome; never ever hack into an authors work and change it! Just as I do not go into a public library and remove pages from books. Examples count more than non-solutions, however examples age faster!
For Windows:
I'm download qt-opensource-windows-x86-5.11.1, icncluded MinGW32.
For MinGW64 I'm download qt-5.5.0-x64-mingw510r0-seh-rev0 and install only compiler.
Configure QtCreator, as says here.
Create new project and add QMAKE_CXXFLAGS += -std=gnu++1z to .pro file (gcc doc).
For test, try compile this simple code:
#include <optional>
std::optional<int> foo()
{
return std::nullopt;
}
int main(int argc, char *argv[])
{
foo();
}
I would like to build Facebook's Proxygen c++ http libraries out of github with Ubuntu 16.04. Here's the environment I set up along with the deps.sh command to install dependencies:
gcc --version
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.1) 5.4.0 20160609
export CPPFLAGS="-std=c++14"
export CXXFLAGS="-std=c++14"
git clone git#github.com:facebook/proxygen.git
cd proxygen/proxygen && ./deps.sh
That got me most of the way through building its folly dependency, but I am getting an incomplete type error:
libtool: compile: g++ -DHAVE_CONFIG_H -I./.. -pthread -I/usr/include -std=c++14 -std=gnu++1y -std=c++14 -MT io/async/AsyncPipe.lo -MD -MP -MF io/async/.deps/AsyncPipe.Tpo -c io/async/AsyncPipe.cpp -fPIC -DPIC -o io/async/.libs/AsyncPipe.o
In file included from /usr/include/c++/5/bits/move.h:57:0,
from /usr/include/c++/5/bits/stl_pair.h:59,
from /usr/include/c++/5/utility:70,
from /usr/include/c++/5/algorithm:60,
from ./../folly/Conv.h:26,
from Conv.cpp:16:
/usr/include/c++/5/type_traits: In instantiation of ‘struct std::make_unsigned<__int128>’:
Conv.cpp:528:52: required from ‘folly::detail::ConversionResult<T> folly::detail::digits_to(const char*, const char*) [with Tgt = __int128]’
Conv.cpp:658:16: required from here
/usr/include/c++/5/type_traits:1757:62: error: invalid use of incomplete type ‘class std::__make_unsigned_selector<__int128, false, false>’
{ typedef typename __make_unsigned_selector<_Tp>::__type type; };
^
/usr/include/c++/5/type_traits:1721:11: note: declaration of ‘class std::__make_unsigned_selector<__int128, false, false>’
class __make_unsigned_selector;
^
/usr/include/c++/5/type_traits: In instantiation of ‘struct std::make_unsigned<__int128 unsigned>’:
Conv.cpp:528:52: required from ‘folly::detail::ConversionResult<T> folly::detail::digits_to(const char*, const char*) [with Tgt = __int128 unsigned]’
Conv.cpp:661:16: required from here
Has anyone tried or solved this? I'm not familiar with the code base yet. Tia.
TL;DR Proxygen needs GNU extensions; use -std=gnu++11 or -std=gnu++14
Why do you need to override C++ standard when building proxygen and its dependencies? Folly itself specifies -std=gnu++1y. If you remove
export CPPFLAGS="-std=c++14"
export CXXFLAGS="-std=c++14"
and try to build it, it almost will, the only change that I had to make to folly is to fix membarrier.
If you insist on using -std=c++14, then the problem actually is not in folly, it's in libstdc++ handling of GNU extensions, this simple line:
typedef std::make_unsigned<__int128>::type int128_type;
Will easily compile with -std=gnu++11 or -std=gnu++1y, but will fail with any of -std=c++11 or -std=c++14. And it's hard to tell, whether it is a bug (because the compiler provides __int128 type (and folly detects that in its configure script, BTW) but C++ library has problems with it) or a feature (because __int128 is an extension in the first place and one should use some GNU variant of standard to properly get it).
I am doing tests for my code with GoogleTest (1.7.0). I must have the tests compiling in both NetBeans (8.0.2) and straight from command line.
NetBeans has GoogleTest integrated as suggested here: https://youtu.be/TS2CTf11k1U.
I have also build GoogleTest from the command line (in different place) with the instructions provided with the package.
The problematic line of code is (a and b are doubles):
std::string input = std::to_string(a) + " " + std::to_string(b);
which gives error: ‘to_string’ is not a member of ‘std’, when compiling with
g++ -isystem -std=c++0x ~/gtest-1.7.0/include -pthread ~/Task1/test_source.cpp libgtest.a -o test_module1_1
as instructed in GoogleTest documentation.
The strange thing here is that when using the "Test" from NetBeans (as seen on video), the tests compile and run correctly.
I am using Ubuntu 14.04 and I have already tried to update g++ (not to a higher version though), and I have also tried specifying the version with -std=c++11 instead of -std=c++0x.
In NetBeans there is this warning visible:
Library File /usr/include/c++/4.8/string
but there is an unresolved #include <stddef.h>
in included /usr/include/_G_config.h
I found out that this might be because multilib and I have also tried to fix that by checking that it is installed. And this doesn't really cause any warnings during compile so it might be just that the IDE is confused.
But conserning the real problem about compile errors:
Is there something wrong with the GoogleTest framework, the compiler or my code?
PS. Preferably don't suggest that I just don't use to_string as this system must be usable by students studying C++11 and really it shouldn't be that they can't use all the functionality that should be supported.
I think your problem is the order in which you're passing command line arguments to gcc
g++ -isystem -std=c++0x ~/gtest-1.7.0/include ...
^^^^^^^^^^^^^^^^^^^
The -isystem flag should be followed by a path that contains headers which you want gcc to treat as system headers. So the -std=c++0x flag is being incorrectly consumed by the -isystem flag. You probably want the command line to be
g++ -std=c++0x -isystem ~/gtest-1.7.0/include ...