Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++14 Support #103

Open
hnefatl opened this issue Aug 9, 2017 · 3 comments
Open

C++14 Support #103

hnefatl opened this issue Aug 9, 2017 · 3 comments

Comments

@hnefatl
Copy link

hnefatl commented Aug 9, 2017

I'm trying to use a library which requires C++14 compiler support, and I've been unable to get x86_64-rumprun-netbsd-g++ to cooperate.

As I couldn't find any references on how to do this, my approach has been to compile rumprun using g++ 5.4.0, which does support C++14. The resulting x86_64-rumprun-netbsd-g++ reports the right version:

> x86_64-rumprun-netbsd-g++ --version
g++ (GCC) 5.4.0

But compiling a simple program using a C++14 feature like std::cbegin:

#include <vector>

int main()
{
    std::vector<int> a { 1, 2, 3 };
    std::vector<int>::const_iterator i = std::cbegin(a);
}

...fails with x86_64-rumprun-netbsd-g++:

> x86_64-rumprun-netbsd-g++ -std=c++14 test.cpp
test.cpp: In function ‘int main(int, char**)’:
test.cpp:6:42: error: ‘cbegin’ is not a member of ‘std’

...but works with g++ 5.4.0:

> g++5 -std=c++14 test.cpp

Is what I'm trying to achieve possible? If so, any advice on what mistake I'm making?

If relevant, the g++ I'm using has been built from source, so isn't the system default. I built rumprun using:

export CC=gcc5
export CXX=g++5
./build-rr.sh -j 4 hw -- -r -j 4
@hnefatl
Copy link
Author

hnefatl commented Aug 9, 2017

Oh, just realised that x86_64-rumprun-netbsd-g++ is just a wrapper script. Don't know how I didn't notice that sooner.

In any case, looks like it passes through to $prefix/libexec/rumprun-x86_64-hw/x86_64--netbsd-c++ (as I built for hw). Calling this file like:

> x86_64--netbsd-c++ -std=c++14 test.cpp

...compiles fine (and even runs correctly on my x86_64 Debian Jessie laptop). So I guess somewhere in the x86_64-rumprun-netbsd-g++ script a parameter's not getting passed through correctly.

Edit: I've noticed that the x86_64-rumprun-netbsd-g++ script invokes --sysroot on the compiler, which I thought could be the issue if the new root didn't have C++14 header files - but it does have them (on my install, at least), so that's not the issue.

Edit 2: If the x86_64-rumprun-netbsd-g++ script is modified to print out the command line it's going to exec before it does, -std=c++14 is there. Here's what mine looked like (newlines added for presentation):

<rumprun path>./rumprun/libexec/rumprun-x86_64-hw/x86_64--netbsd-c++
-mno-red-zone
-no-integrated-cpp
--sysroot <rumprun path>./rumprun/rumprun-x86_64
-specs=<rumprun path>./rumprun/rumprun-x86_64/lib/specs-compile_or_ferment
-Wl,-r -Wl,-u,main
-std=c++14 test.cpp
<rumprun path>./rumprun/rumprun-x86_64/share/x86_64-rumprun-netbsd-recipe.s
-lc++ -lunwind

So I suppose it's actually an issue of conflicting arguments somewhere.

Edit 3: Okay now I'm confused - I dug around some more, and none of the switches seem like they could conflict with -std=c++14 except the -spec one, which overrides the default compiler spec with a new one. In my spec file, the relevant lines seem to be:

*cpp_options:
-nostdinc -isystem <rumprun path>./rumprun/rumprun-x86_64/include %{,c++:%{!std=*:-std=c++11}} %{,c++:-isystem <rumprun path>./rumprun/rumprun-x86_64/include/c++} %(old_cpp_options) -D__NetBSD__  -Ulinux -U__linux -U__linux__ -U__gnu_linux__ -D__RUMPRUN__

...

*cc1plus:
%{!std=*:-std=c++11}

...which if my understanding of these docs is correct, should be doing something like "if the std switch isn't given, then add the switch -std=c++11". This seems like it shouldn't conflict, then, as if I specify no std switch it doesn't compile either. I have tried changing both occurrences to c++14 and running the x86_64-rumprun-netbsd-g++ script with and without a std switch, but nothing different happens.

@hnefatl
Copy link
Author

hnefatl commented Aug 9, 2017

Okay, I've checked through most of the flags now and I am completely confused. It looks like x86_64-rumprun-netbsd-g++ is working with C++14, it's just unable to find the right header.

Manually peeking inside <rumprun path>/rumprun/rumprun-x86_64/include/c++/iterator shows all the C++14 and even some C++17 function declarations, as expected. As evident from the below verbose output dump from x86_64-rumprun-netbsd-g++ -v -std=c++14 test.cpp it's even looking in the right places.

Using #include <<rumprun path>/rumprun/rumprun-x86_64/include/c++/iterator> didn't work either, so... yeah. I'm stumped.

{rumprun path}/rumprun/libexec/rumprun-x86_64-hw/x86_64--netbsd-c++ -mno-red-zone -no-integrated-cpp --sysroot {rumprun path}/rumprun/rumprun-x86_64 -specs={rumprun path}/rumprun/rumprun-x86_64/lib/specs-compile_or_ferment -Wl,-r -Wl,-u,main -v -std=c++14 test.cpp {rumprun path}/rumprun/rumprun-x86_64/share/x86_64-rumprun-netbsd-recipe.s -lc++ -lunwind
Using built-in specs.
Reading specs from {rumprun path}/rumprun/rumprun-x86_64/lib/specs-compile_or_ferment
rename spec cpp_options to old_cpp_options
rename spec cc1_options to old_cc1_options
rename spec link_libgcc to old_link_libgcc
rename spec libgcc to old_libgcc
COLLECT_GCC={gcc5 path}/bin/g++
COLLECT_LTO_WRAPPER={gcc5 path}libexec/gcc/x86_64-unknown-linux-gnu/5.4.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../configure --prefix={gcc path} --enable-languages=c,c++ --disable-multilib
Thread model: posix
gcc version 5.4.0 (GCC) 
COLLECT_GCC_OPTIONS='-mno-red-zone' '-no-integrated-cpp' '-specs={rumprun path}/rumprun/rumprun-x86_64/lib/specs-compile_or_ferment' '-v' '-std=c++14' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 {gcc5 path}libexec/gcc/x86_64-unknown-linux-gnu/5.4.0/cc1plus -E -nostdinc -isystem {rumprun path}/rumprun/rumprun-x86_64/include -isystem {rumprun path}/rumprun/rumprun-x86_64/include/c++ -quiet -v -imultiarch x86_64-linux-gnu -isysroot {rumprun path}/rumprun/rumprun-x86_64 -D_GNU_SOURCE test.cpp -mno-red-zone -mtune=generic -march=x86-64 -std=c++14 -D__NetBSD__ -Ulinux -U__linux -U__linux__ -U__gnu_linux__ -D__RUMPRUN__ -o /tmp/ccoaKcYx.ii
#include "..." search starts here:
#include <...> search starts here:
 {rumprun path}/rumprun/rumprun-x86_64/include
 {rumprun path}/rumprun/rumprun-x86_64/include/c++
End of search list.
COLLECT_GCC_OPTIONS='-mno-red-zone' '-no-integrated-cpp' '-specs={rumprun path}/rumprun/rumprun-x86_64/lib/specs-compile_or_ferment' '-v' '-std=c++14' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 {gcc5 path}libexec/gcc/x86_64-unknown-linux-gnu/5.4.0/cc1plus -fpreprocessed /tmp/ccoaKcYx.ii -quiet -dumpbase test.cpp -mno-red-zone -mtune=generic -march=x86-64 -auxbase test -std=c++14 -version -mno-red-zone -fno-stack-protector -fno-builtin-sin -fno-builtin-sinf -fno-builtin-cos -fno-builtin-cosf -o /tmp/ccwEyqmR.s
GNU C++14 (GCC) version 5.4.0 (x86_64-unknown-linux-gnu)
	compiled by GNU C version 5.4.0, GMP version 4.3.2, MPFR version 2.4.2, MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C++14 (GCC) version 5.4.0 (x86_64-unknown-linux-gnu)
	compiled by GNU C version 5.4.0, GMP version 4.3.2, MPFR version 2.4.2, MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: ad108975c825c71463335b0918a936e6
test.cpp: In function ‘int main(int, char**)’:
test.cpp:10:42: error: ‘cbegin’ is not a member of ‘std’
     std::vector::const_iterator i = std::cbegin(a);
                                          ^
COLLECT_GCC_OPTIONS='-mno-red-zone' '-no-integrated-cpp' '-specs={rumprun path}/rumprun/rumprun-x86_64/lib/specs-compile_or_ferment' '-v' '-std=c++14' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 as -v --64 -o /tmp/cc3BXHYb.o {rumprun path}/rumprun/rumprun-x86_64/share/x86_64-rumprun-netbsd-recipe.s
GNU assembler version 2.28 (x86_64-linux-gnu) using BFD version (GNU Binutils for Debian) 2.28

@oberstet
Copy link

I am also interested in gcc with c++ 14 (or at least 11) .. actually I need Boost/ASIO and https://github.com/crossbario/autobahn-cpp, which is pretty heavy on templates, std::future etc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants