Menu

#20 Build fails unless using -std=c++11

v1.15
open
nobody
None
5
2020-07-08
2020-07-07
No

Hi, rsyncrypto 1.14 doesn't build on macOS 10.13. The errors start with:

/usr/bin/clang++ -DHAVE_CONFIG_H -I.   -I/opt/local/include  -pipe -Os -stdlib=libc++ -arch x86_64 -MT crypto.o -MD -MP -MF .deps/crypto.Tpo -c -o crypto.o crypto.cpp
crypto.cpp:176:12: error: calling a private constructor of class 'std::__1::unique_ptr<key, std::__1::default_delete<key> >'
    return ret;
           ^
/Library/Developer/CommandLineTools/usr/include/c++/v1/memory:2436:3: note: declared private here
  unique_ptr(unique_ptr&);
  ^
crypto.cpp:249:15: error: use of overloaded operator '==' is ambiguous (with operand types 'std::unique_ptr<key>' and 'long')
    if( header==NULL ) {
        ~~~~~~^ ~~~~
/Library/Developer/CommandLineTools/usr/include/c++/v1/memory:2900:1: note: candidate function [with _T1 = key, _D1 = std::__1::default_delete<key>]
operator==(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
^
crypto.cpp:249:15: note: built-in candidate operator==(int, long)
    if( header==NULL ) {
              ^
crypto.cpp:249:15: note: built-in candidate operator==(unsigned __int128, long)
crypto.cpp:249:15: note: built-in candidate operator==(unsigned long long, long)
crypto.cpp:249:15: note: built-in candidate operator==(unsigned long, long)
crypto.cpp:249:15: note: built-in candidate operator==(unsigned int, long)
crypto.cpp:249:15: note: built-in candidate operator==(__int128, long)
crypto.cpp:249:15: note: built-in candidate operator==(float, long)

(I omitted a zillion similar built-in candidates that follow.)

It builds fine if I add -std=c++11 to CXXFLAGS. (This version of clang defaults to an earlier C++ standard.) If you require C++11, you should make your build system add that flag automatically.

Discussion

  • Shachar Shemesh

    Shachar Shemesh - 2020-07-07

    Adding that flag automatically is not as simple as it sounds. Not all compilers require it, and it is not guaranteed that all compiler will even know how to parse std=c++11. As such, having the user add it if needed is the only option that makes sense.

    With that said, it might be a good idea to add a test to configure to make sure the compiler support C++11 features, to make the failure clearer.

     
  • Ryan Carsten Schmidt

    Do you know which compilers don't require -std=c++11 to compile this?

     
    • Shachar Shemesh

      Shachar Shemesh - 2020-07-08

      That is the wrong question. The right question is do you know for sure that all compilers support that command line?

      As for your other question: both clang of versions 6 and up (possibly earlier) and g++ of versions 6 and up (again, possibly earlier) do not need any special compilation flags to support C++11 features (specifically, unique_ptr). That flags was a transition period requirement.

      The only reason rsyncrypto was written to make it sound like it was optional was because, when written, std::map was the only thing available with the standard, and that is a tree, not a hash table. To make the program more versatile, I used boost where available, and a fallback where not.

      When C++11 came out, I transitioned the code to use that instead, so at the time it was optional. It no longer is, as you've noticed yourself, and the configure script needs to be updated to reflect that.

       
  • Ryan Carsten Schmidt

    I tried building on a much older system running Mac OS X 10.4 and using the MacPorts version of Apple gcc 4.2.1. When not using -std=c++11 it failed with:

    /opt/local/bin/g++-apple-4.2 -DHAVE_CONFIG_H -I.   -I/opt/local/include  -pipe -Os -arch i386 -MT main.o -MD -MP -MF .deps/main.Tpo -c -o main.o main.cpp
    In file included from main.cpp:32:
    rsyncrypto.h:97: error: expected initializer before '<' token
    In file included from crypto.h:34,
                     from main.cpp:34:
    crypt_key.h:54: error: ISO C++ forbids declaration of 'unique_ptr' with no type
    crypt_key.h:54: error: invalid use of '::'
    crypt_key.h:54: error: expected ';' before '<' token
    crypt_key.h:55: error: ISO C++ forbids declaration of 'unique_ptr' with no type
    crypt_key.h:55: error: invalid use of '::'
    crypt_key.h:55: error: expected ';' before '<' token
    In file included from main.cpp:34:
    crypto.h:42: error: expected constructor, destructor, or type conversion before '<' token
    crypto.h:49: error: expected constructor, destructor, or type conversion before '<' token
    main.cpp:38: error: expected constructor, destructor, or type conversion before '<' token
    main.cpp: In function 'int main(int, char**)':
    main.cpp:138: error: 'changes_log' was not declared in this scope
    main.cpp:138: error: 'unique_ptr' is not a member of 'std'
    main.cpp:138: error: expected primary-expression before '>' token
    

    Apple gcc 4.2.1 doesn't support C++11 and yet your build is trying to use unique_ptr which is a C++11 feature. So it seems to me that you do require C++11.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.