Darin
Darin

Reputation: 508

get a basic c++ program to compile using clang++ on Ubuntu 16

I'm running into problems compiling on Ubuntu 16.04 LTS (server). It compiles okay if I don't include the -std=c++11 bit. Clang version is 3.8.

>cat foo.cpp
#include <string>
#include <iostream>
using namespace std;

int main(int argc,char** argv) {
    string s(argv[0]);
    cout << s << endl;
}


>clang++ -std=c++11 -stdlib=libc++ foo.cpp
In file included from foo.cpp:1:
/usr/include/c++/v1/string:1938:44: error: 'basic_string<_CharT, _Traits, _Allocator>' is missing exception specification
      'noexcept(is_nothrow_copy_constructible<allocator_type>::value)'
basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a)
                                           ^
/usr/include/c++/v1/string:1326:40: note: previous declaration is here
    _LIBCPP_INLINE_VISIBILITY explicit basic_string(const allocator_type& __a)
                                       ^
1 error generated.

Upvotes: 23

Views: 6140

Answers (2)

VZ.
VZ.

Reputation: 22753

Until the Debian bug mentioned in Mike Kinghan's reply is fixed, just adding the missing (but required) noexcept specification to the ctor definition manually allows to work around the problem, i.e. you could just add

#if _LIBCPP_STD_VER <= 14
    _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
#else
    _NOEXCEPT
#endif

after the line 1938 of /usr/include/c++/v1/string.

Upvotes: 22

Mike Kinghan
Mike Kinghan

Reputation: 61575

You have installed libc++-dev on ubuntu 16.04 in the (correct) expectation that it ought to let you build with clang++ using libc++ and its headers for your standard library.

It ought to, but in the presence of std=c++11 (or later standard), it doesn't, because of Debian bug #808086, which you have run into.

If you wish to compile with clang++ to the C++11 standard or later, then until ubuntu gets a fix for this you will have to do so without libc++, using libstdc++ (the GNU C++ standard library) instead, which is the default behaviour.

clang++ -std=c++11 foo.cpp

or:

clang++ -std=c++11 -stdlib=libstdc++ foo.cpp

will work.

Upvotes: 20

Related Questions