Bitcoin-abc: ./amount.h:76:63: error: can't initialize friend function 'operator*'

Created on 23 Oct 2017  Â·  28Comments  Â·  Source: Bitcoin-ABC/bitcoin-abc

I'm trying to build the client with the latest github checkout,, using the following commands:

./autogen.sh
./configure --enable-cxx --disable-shared --with-pic --prefix=/opt/bitcoin-cash-build PKG_CONFIG_PATH=/opt/openssl/lib/pkgconfig LIBS=-Wl,-rpath,/opt/openssl/lib
make

The result of make is:

Making all in src
make[1]: Entering directory `/opt/bitcoin-cash/src'
make[2]: Entering directory `/opt/bitcoin-cash/src'
  CXX      consensus/libbitcoinconsensus_la-merkle.lo
In file included from ./primitives/transaction.h:9:0,
                 from ./primitives/block.h:9,
                 from consensus/merkle.h:11,
                 from consensus/merkle.cpp:5:
./amount.h:76:63: error: can't initialize friend function 'operator*'
     friend Amount operator*(const double a, const Amount b) = delete;
                                                               ^
make[2]: *** [consensus/libbitcoinconsensus_la-merkle.lo] Error 1
make[2]: Leaving directory `/opt/bitcoin-cash/src'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/opt/bitcoin-cash/src'
make: *** [all-recursive] Error 1

This is on OEL. I previously did this without issue at the time of the fork using the same process.

I have no local changes (this is a fresh clone).

I'm afraid I'm not familiar with the code, so I may have overlooked something obvious.

Most helpful comment

In centos I upgrade gcc from 4.8.5 to gcc 7.2.1 and disable test compile

yum install centos-release-scl -y    
yum install devtoolset-7-toolchain -y
scl enable devtoolset-7 bash
gcc --version
./configure LDFLAGS="-L${BDB_PREFIX}/lib/" CPPFLAGS="-I${BDB_PREFIX}/include/" --without-gui --disable-tests --disable-gui-tests --disable-bench

All 28 comments

@sparsecloud : We've noticed several C++ compiler versions having problems with this declaration which has been put in for defensive programming purposes.

You can safely comment out that line for your build without affecting the functioning of the software.

Removing the indicated line gets me a successful compile on CentOS 7 (gcc 4.8.5). What I don't get is that I think this compiler shouldn't have had a problem with it. Supposedly N2346 has been supported since gcc 4.4. I'd love to see a fuller explanation of what's going on here.

@error10 : Thanks for the report. All I can add right now is that gcc 7.1 and 7.2 compile successully with that declaration.

It's hapenning on Travis too

https://github.com/Bitcoin-ABC/bitcoin-abc/issues/101

(closing that issue, since it seems to be a duplicate)

Even with gcc-7 added to travis (via ubuntu-toolchain-r-test), this still fails. :(

The fix for Travis is already in the upstream, but hasn't been pushed to GH yet.

https://reviews.bitcoinabc.org/rABC31b68eb0b59ba2721d31b9668831de6fc226da03

Unfortunately some Travis functionality is lost due to moving to modern C++ features.
It's very likely that Travis CI will be dropped in ABC in favor of a solution which can be better maintained.

Having same issue when trying to compile on Debian

In file included from ./primitives/transaction.h:9:0,
                 from ./primitives/block.h:9,
                 from consensus/merkle.h:11,
                 from consensus/merkle.cpp:5:
./amount.h:76:63: error: can't initialize friend function 'operator*'
     friend Amount operator*(const double a, const Amount b) = delete;
                                                               ^
Makefile:7920: recipe for target 'consensus/libbitcoinconsensus_la-merkle.lo' failed
make[2]: *** [consensus/libbitcoinconsensus_la-merkle.lo] Error 1
make[2]: Leaving directory '/home/wallet/bitcoinnew/src'
Makefile:9472: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/home/wallet/bitcoinnew/src'
Makefile:678: recipe for target 'all-recursive' failed
make: *** [all-recursive] Error 1

@AdvancedStyle : as I wrote up above:

You can safely comment out that line for your build without affecting the functioning of the software.

Commented that line now get a new compile error:

leveldb/util/logging.cc: In function ‘bool leveldb::ConsumeDecimalNumber(leveldb::Slice*, uint64_t*)’:
leveldb/util/logging.cc:58:40: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
           (v == kMaxUint64/10 && delta > kMaxUint64%10)) {
                                        ^
  CXX      leveldb/util/leveldb_libleveldb_a-options.o
  CXX      leveldb/util/leveldb_libleveldb_a-status.o
  CXX      leveldb/port/leveldb_libleveldb_a-port_posix.o
leveldb/port/port_posix.cc: In function ‘bool leveldb::port::HasAcceleratedCRC32C()’:
leveldb/port/port_posix.cc:60:15: warning: ‘ecx’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   return (ecx & (1 << 20)) != 0;
               ^
  AR       leveldb/libleveldb.a
  CXX      leveldb/port/leveldb_libleveldb_sse42_a-port_posix_sse.o
  AR       leveldb/libleveldb_sse42.a
  CXX      leveldb/helpers/memenv/leveldb_libmemenv_a-memenv.o
  AR       leveldb/libmemenv.a
  CXXLD    bitcoind
  CXX      seeder/bitcoin_seeder-main.o
In file included from seeder/main.cpp:3:0:
seeder/db.h: In member function ‘void CAddrDb::GetMany(std::vector<CServiceResult>&, int, int&)’:
seeder/db.h:416:34: warning: missing initializer for member ‘CServiceResult::service’ [-Wmissing-field-initializers]
             CServiceResult ip = {};
                                  ^
seeder/db.h:416:34: warning: missing initializer for member ‘CServiceResult::fGood’ [-Wmissing-field-initializers]
seeder/db.h:416:34: warning: missing initializer for member ‘CServiceResult::nBanTime’ [-Wmissing-field-initializers]
seeder/db.h:416:34: warning: missing initializer for member ‘CServiceResult::nHeight’ [-Wmissing-field-initializers]
seeder/db.h:416:34: warning: missing initializer for member ‘CServiceResult::nClientV’ [-Wmissing-field-initializers]
seeder/db.h:416:34: warning: missing initializer for member ‘CServiceResult::strClientV’ [-Wmissing-field-initializers]
seeder/db.h:416:34: warning: missing initializer for member ‘CServiceResult::ourLastSuccess’ [-Wmissing-field-initializers]
  CXX      seeder/libbitcoin_seeder_a-bitcoin.o
In file included from seeder/bitcoin.cpp:3:0:
seeder/db.h: In member function ‘void CAddrDb::GetMany(std::vector<CServiceResult>&, int, int&)’:
seeder/db.h:416:34: warning: missing initializer for member ‘CServiceResult::service’ [-Wmissing-field-initializers]
             CServiceResult ip = {};
                                  ^
seeder/db.h:416:34: warning: missing initializer for member ‘CServiceResult::fGood’ [-Wmissing-field-initializers]
seeder/db.h:416:34: warning: missing initializer for member ‘CServiceResult::nBanTime’ [-Wmissing-field-initializers]
seeder/db.h:416:34: warning: missing initializer for member ‘CServiceResult::nHeight’ [-Wmissing-field-initializers]
seeder/db.h:416:34: warning: missing initializer for member ‘CServiceResult::nClientV’ [-Wmissing-field-initializers]
seeder/db.h:416:34: warning: missing initializer for member ‘CServiceResult::strClientV’ [-Wmissing-field-initializers]
seeder/db.h:416:34: warning: missing initializer for member ‘CServiceResult::ourLastSuccess’ [-Wmissing-field-initializers]
  CXX      seeder/libbitcoin_seeder_a-db.o
In file included from seeder/db.cpp:1:0:
seeder/db.h: In member function ‘void CAddrDb::GetMany(std::vector<CServiceResult>&, int, int&)’:
seeder/db.h:416:34: warning: missing initializer for member ‘CServiceResult::service’ [-Wmissing-field-initializers]
             CServiceResult ip = {};
                                  ^
seeder/db.h:416:34: warning: missing initializer for member ‘CServiceResult::fGood’ [-Wmissing-field-initializers]
seeder/db.h:416:34: warning: missing initializer for member ‘CServiceResult::nBanTime’ [-Wmissing-field-initializers]
seeder/db.h:416:34: warning: missing initializer for member ‘CServiceResult::nHeight’ [-Wmissing-field-initializers]
seeder/db.h:416:34: warning: missing initializer for member ‘CServiceResult::nClientV’ [-Wmissing-field-initializers]
seeder/db.h:416:34: warning: missing initializer for member ‘CServiceResult::strClientV’ [-Wmissing-field-initializers]
seeder/db.h:416:34: warning: missing initializer for member ‘CServiceResult::ourLastSuccess’ [-Wmissing-field-initializers]
  CC       seeder/libbitcoin_seeder_a-dns.o
seeder/dns.c: In function ‘write_record_a’:
seeder/dns.c:176:5: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
     for (int i = 0; i < 4; i++)
     ^
seeder/dns.c:176:5: note: use option -std=c99, -std=gnu99, -std=c11 or -std=gnu11 to compile your code
seeder/dns.c: In function ‘write_record_aaaa’:
seeder/dns.c:200:5: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
     for (int i = 0; i < 16; i++)
     ^
seeder/dns.c: In function ‘dnsserver’:
seeder/dns.c:547:9: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
         for (struct cmsghdr *hdr = CMSG_FIRSTHDR(&msg); hdr;
         ^
Makefile:4347: recipe for target 'seeder/libbitcoin_seeder_a-dns.o' failed
make[2]: *** [seeder/libbitcoin_seeder_a-dns.o] Error 1
make[2]: Leaving directory '/home/wallet/bitcoinnew/src'
Makefile:9472: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/home/wallet/bitcoinnew/src'
Makefile:678: recipe for target 'all-recursive' failed
make: *** [all-recursive] Error 1

Hi @AdvancedStyle,

Please try adding --without-seeder to your configure command and make again.

This just skips the building of the DNS seeder code which has been added recently. Most people don't use it. There is cleanup we need to do around that code and its build.

@ftrader thanks, I will try to use the updated .travis.yml

Now, travis build also fails, but only the last two targets, both with The job exceeded the maximum time limit for jobs, and has been terminated.; the first two targets build well (in 36 minutes)

@AdvancedStyle for me helps comment line number 76 in src/amount.h:
// DO NOT IMPLEMENT
//friend Amount operator*(const double a, const Amount b) = delete;

@ftrader --without-seeder - this option not help

ubuntu 14.04 got same issues

@vetal20600 : Looks like you're trying to use the native compiler (4.8.4?) on Trusty.
Unfortunately you'll need to install a newer compiler.
This is what we also had to do on the Trusty platforms we use for the Travis builds of ABC.

My advice is that for Ubuntu 14.04, you pull in g++7 package from Ubuntu toolchain repository.
See instructions here for adding repo and updating:
https://launchpad.net/~ubuntu-toolchain-r/+archive/ubuntu/test?field.series_filter=trusty

Try building then (re-run configure and add CC=gcc7 CXX=g++7 to its options).

I just built it _with_ the seeder on my Ubuntu 14.04 VM (no-gui build though), which may or may not be clean. I have the gcc7 and g++7 packages installed. If you try that and still have further troubles building it, please open a separate Issue "Building ABC 0.x.y on Ubuntu 14.04" .

This is my issue:

Making all in src
make[1]: Entering directory `/root/wallets/bitcoin-abc/src'
make[2]: Entering directory `/root/wallets/bitcoin-abc/src'
  CC       seeder/libbitcoin_seeder_a-dns.o
seeder/dns.c: In function 'write_record_a':
seeder/dns.c:176:5: error: 'for' loop initial declarations are only allowed in C99 mode
     for (int i = 0; i < 4; i++)
     ^
seeder/dns.c:176:5: note: use option -std=c99 or -std=gnu99 to compile your code
seeder/dns.c: In function 'write_record_aaaa':
seeder/dns.c:200:5: error: 'for' loop initial declarations are only allowed in C99 mode
     for (int i = 0; i < 16; i++)
     ^
seeder/dns.c: In function 'dnsserver':
seeder/dns.c:547:9: error: 'for' loop initial declarations are only allowed in C99 mode
         for (struct cmsghdr *hdr = CMSG_FIRSTHDR(&msg); hdr;
         ^
make[2]: *** [seeder/libbitcoin_seeder_a-dns.o] Error 1
make[2]: Leaving directory `/root/wallets/bitcoin-abc/src'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/root/wallets/bitcoin-abc/src'
make: *** [all-recursive] Error 1

Workaround is: to comment line 76 and use this key: _--without-seeder_

This fixed it for me:
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-7
sudo apt-get install g++-7
./configure CC=gcc-7 CXX=g++-7
make

Note the "-" before the 7 - that is missing from some of the comments above.
Guess someone should update build instructions...

This is due to a bug in g++4.8 . You need to use a more recent version of g++ or clang.

v0.16.1 is not compiling on older systems.

Why do you accidentally switched to the new g++ ? What's the point? There is still a lot of people who do use e.g. Debian Jessie 8 with g++ 4.9.2-10.

Here is a compilation error I'm getting:

In file included from ./primitives/transaction.h:9:0,
                 from ./primitives/block.h:9,
                 from consensus/merkle.h:11,
                 from consensus/merkle.cpp:5:
./amount.h:76:73: error: can't initialize friend function 'operator*'
     friend constexpr Amount operator*(const double a, const Amount b) = delete;
                                                                         ^
  CXX      script/libbitcoinconsensus_la-interpreter.lo
  CXX      script/libbitcoinconsensus_la-script.lo
Makefile:7920: recipe for target 'consensus/libbitcoinconsensus_la-merkle.lo' failed
make[2]: *** [consensus/libbitcoinconsensus_la-merkle.lo] Error 1
make[2]: *** Waiting for unfinished jobs....
In file included from ./primitives/transaction.h:9:0,
                 from primitives/transaction.cpp:6:
./amount.h:76:73: error: can't initialize friend function 'operator*'
     friend constexpr Amount operator*(const double a, const Amount b) = delete;
                                                                         ^
Makefile:7941: recipe for target 'primitives/libbitcoinconsensus_la-transaction.lo' failed
make[2]: *** [primitives/libbitcoinconsensus_la-transaction.lo] Error 1
In file included from ./primitives/transaction.h:9:0,
                 from ./primitives/block.h:9,
                 from primitives/block.cpp:6:
./amount.h:76:73: error: can't initialize friend function 'operator*'
     friend constexpr Amount operator*(const double a, const Amount b) = delete;
                                                                         ^
In file included from ./primitives/transaction.h:9:0,
                 from script/interpreter.h:9,
                 from script/interpreter.cpp:6:
./amount.h:76:73: error: can't initialize friend function 'operator*'
     friend constexpr Amount operator*(const double a, const Amount b) = delete;
                                                                         ^
In file included from ./primitives/transaction.h:9:0,
                 from script/bitcoinconsensus.cpp:8:
./amount.h:76:73: error: can't initialize friend function 'operator*'
     friend constexpr Amount operator*(const double a, const Amount b) = delete;
                                                                         ^
Makefile:7962: recipe for target 'script/libbitcoinconsensus_la-interpreter.lo' failed

Maybe it's better to provide better compatibility instead of breaking things?

Thank you.

What about you post a bug report with the error you get ?

Le 13 nov. 2017 22:23, "gituser" notifications@github.com a écrit :

v0.16.1 is not compiling on older systems.

Why do you accidentally switched to the new g++ ? What's the point? There
is still a lot of people who do use e.g. Debian Jessie 8 with g++ 4.9.2-10.

Maybe it's better to provide better compatibility instead of breaking
things?

Thank you.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/Bitcoin-ABC/bitcoin-abc/issues/98#issuecomment-344062930,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AA0IaSAGRkZgcL8CFQtp6nKncT6qCpKBks5s2LNigaJpZM4QCmgT
.

@deadalnix just did.

EDIT:

if I do apply the workaround of commenting //friend constexpr Amount operator*(const double a, const Amount b) = delete; and adding build options of --without-seeder I get another error when building v0.16.1 - https://paste.fedoraproject.org/paste/K~8qVBfOIGenYHEZ4u-OGQ

Just in case you're wondering boost is 1.55.0+dfsg-3 (1.55.0.2) which comes with Debian Jessie.

v0.16.0 yesterday built just fine with the workaround.

@deadalnix
Please read my post above (in case you're checking through e-mail), because I've edited it with the log.

Thank you.

I indeed was answering by mail. Can you open a separate issue with that one ?

@Mengerian can you take a look and see if the build documentation needs to be updated?

In centos I upgrade gcc from 4.8.5 to gcc 7.2.1 and disable test compile

yum install centos-release-scl -y    
yum install devtoolset-7-toolchain -y
scl enable devtoolset-7 bash
gcc --version
./configure LDFLAGS="-L${BDB_PREFIX}/lib/" CPPFLAGS="-I${BDB_PREFIX}/include/" --without-gui --disable-tests --disable-gui-tests --disable-bench

Just for the record, this is the mentioned bug in GCC, which got fixed in GCC 5.1.

Was this page helpful?
0 / 5 - 0 ratings