-4

Hey Stackoverflow Community, right now i have have the following problem: I want to compile c++ with mac osx.10.11. But every time i want to make the code it gives me an errorcode. I already googled that, but i found nothing.

hashGenesisBlock = uint256("0x01");
if (true && genesis.GetHash() != hashGenesisBlock)
        {
            Logprintf("recalculating params for mainnet.\n");
            Logprintf("old mainnet genesis nonce: %s\n", genesis.nNonce.ToString().c_str());
            Logprintf("old mainnet genesis hash:  %s\n", hashGenesisBlock.ToString().c_str());
            // deliberately empty for loop finds nonce value.
            for(genesis.nNonce == 0; genesis.GetHash() > bnProofOfWorkLimit; genesis.nNonce++){ } 
            Logprintf("new mainnet genesis merkle root: %s\n", genesis.hashMerkleRoot.ToString().c_str());
            Logprintf("new mainnet genesis nonce: %s\n", genesis.nNonce.ToString().c_str());
            Logprintf("new mainnet genesis hash: %s\n", genesis.GetHash().ToString().c_str());
        }

The error message:

Making all in src
  CXX      libgamebit_common_a-chainparams.o
chainparams.cpp:143:13: error: use of undeclared identifier 'Logprintf'
            Logprintf("recalculating params for mainnet.\n");
            ^
chainparams.cpp:144:72: error: member reference base type 'uint32_t'
      (aka 'unsigned int') is not a structure or union
  ...Logprintf("old mainnet genesis nonce: %s\n", genesis.nNonce.ToString().c...

Do you have any ideas why im getting this kind of error? Actually im trying to compile bitcoind.

I hope you can help me. Thanks!

  • How is `genesis` declared? – NathanOliver Jun 05 '17 at 16:40
  • Do you miss to include a header file? The one containing the declaration of `Logprintf`? – Some programmer dude Jun 05 '17 at 16:41
  • And what is the purpose of `if (true && ...`? – Some programmer dude Jun 05 '17 at 16:41
  • Lastly, what is `genesis.nNonce`? Is it an `uint32_t` variable? You are programming in C++, not C# or Java or any other language where integers are (or could be) objects. Perhaps you should be reading about the `printf` [format macro constants](http://en.cppreference.com/w/cpp/types/integer#Format_macro_constants)? – Some programmer dude Jun 05 '17 at 16:43
  • @Someprogrammerdude: I've seen that a few times! It is so you can easily disable/enable pieces of code just by changing that `true` for a `false`. – rodrigo Jun 05 '17 at 16:43
  • there is an #include "chainparamsseeds.h" in which i found the delcaration of genesis like this: const CBlock& GenesisBlock() const { return genesis; } – Daniel Beller Jun 05 '17 at 16:45
  • 1
    The init-decl of your for loop *really* looks like `genesis.nNonce == 0;` ? What fiend wrote this "thing" anyway? – WhozCraig Jun 05 '17 at 16:46
  • logprintf is sometimes used to print to a debug file...is that what you are trying to do? You must be missing an interface file OR you are miss typing the name of the method in the interface implementation...anayway...Welcome to Stack Overflow. Please take the time to read The Tour and refer to the material from the Help Center what and how you can ask here. Please provide a Minimal, Complete, and Verifiable example that reproduces your problem, and mention error messages verbatim in your question. – Dr t Jun 05 '17 at 16:57

1 Answers1

2

You should concentrate on the first compiler error:

error: use of undeclared identifier 'Logprintf'

That is, you are using this identifier Logprintf, probably a function, but it is not defined. Likely, you are missing a #include that defines it.

The next error:

error: member reference base type 'uint32_t'

if you look at line 144, column 72, it is this one:

Logprintf("old mainnet genesis nonce: %s\n", genesis.nNonce.ToString()
                                                           ^
                                                  column 72|

So your nNonce is of type uint32_t and you are trying to call member function ToString() on it. But basic types in C++ do not have member functions, only structures (ie, classes) and unions have.

I suspect that you are trying to compile some C++/CLI code with a pure C++ compiler. I'm afraid some translation will be needed.

This last error, you can fix, once you have the proper definition of Logprintf, by writing:

Logprintf("old mainnet genesis nonce: %u\n", (unsigned)genesis.nNonce);
rodrigo
  • 94,151
  • 12
  • 143
  • 190
  • 1
    It's not C++/CLI, it's based on the Bitcoin source code which uses [`ToString()`](https://github.com/bitcoin/bitcoin/blob/master/src/uint256.h#L54) and `GetHash()` (versus `GetHashCode()`, which C# and C++/CLI have). – cdhowie Jun 05 '17 at 16:51
  • @cdhowie: Ah, that makes sense. But in this code `nNonce` is of type `uint32_t`, not `uint256`. Anyway, removing the `.ToString().c_str()` and replacing the `%s` with `%d` should just work. – rodrigo Jun 05 '17 at 16:53
  • Right. My suspicion is that it's just bitrot. There was a time when the Bitcoin code used a lot of wrapper types to provide formatting members around basic numeric types. (The original author didn't really know idiomatic C++ very well and didn't know that was an anti-pattern.) A lot of that stuff has been patched out, but I suspect that this is old code that builds using Bitcoin's own headers, and hasn't been updated in a long time. – cdhowie Jun 05 '17 at 16:56
  • Thanks for your answers! Just found out that LogPrint is declared like this: static inline int LogPrint(const char* category, const char* format) – Daniel Beller Jun 05 '17 at 17:04
  • But im getting still errors. Right now my logprint looks like this: "LogPrint("old mainnet genesis nonce:", genesis.nNonce);" – Daniel Beller Jun 05 '17 at 17:06
  • I solved it. The right way to use the print command was: "LogPrint("chainparams","old mainnet genesis nonce: %s\n", (unsigned)genesis.nNonce);" Had to call the name of the file in first place...lol – Daniel Beller Jun 05 '17 at 18:14