<p>As SajithP commented:</p>

<blockquote>
  <p>modify the makefile to include the object of the class which has the chainActive as a member. e.g 'x.o' where chainActive is a member of class 'x' </p>
</blockquote>

CC BY-SA 4.0
2018-11-14T09:36:54.623Z
2018-11-14T09:36:54.623Z
RedGrittyBrick
<p>I want to call chainActive.Tip()->nHeight in core.cpp. It is not possible, I am interested in every idea. </p>

<p><a href="https://github.com/LIMXTEC/BitSend/blob/DEV-joshafest/src/core.cpp" rel="nofollow noreferrer">https://github.com/LIMXTEC/BitSend/blob/DEV-joshafest/src/core.cpp</a></p>

<p>Here is an example :</p>

<pre><code>bool GetH()
{   
    int nBlockHeight = chainActive.Tip()-&gt;nHeight;  
    if(nBlockHeight &lt; FORKX17_Main_Net ) 
        return true;    
    else 
        return false; 
    }
}

uint256 CBlockHeader::GetHash() const 
{   
    if (GetH())     
    {
        return HashX11(BEGIN(nVersion), END(nNonce)); 
    }
    else    
    {
       return HashX17(BEGIN(nVersion), END(nNonce));    
    }
}
</code></pre>

<p>Also that is not possible:</p>

<pre><code>CBlockIndex* pindexPrev = chainActive.Tip();
if (pindexPrev-&gt;nHeight &lt;= FORKX17_Main_Net)
</code></pre>

<p><a href="https://i.sstatic.net/EoH5U.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/EoH5U.jpg" alt="enter image description here"></a></p>

CC BY-SA 3.0
2016-06-26T03:18:30.813Z
Looks like you need to `#include "main.h"`?
Nate Eldredge
CC BY-SA 3.0
2016-06-26T06:53:20.953Z
Yes I use main.h.
#include "core.h"
#include "util.h"
#include "main.h"
#include "uint256.h"
cgminer-0
CC BY-SA 3.0
2017-12-25T11:57:33.363Z
This is due to missing the object of the class which has 'chainActive()' method. So including which ever the file that has the method. In case if it gives further different undefined reference errors; find the file that contains the method; include it; until it compiles ;)
SajithP
CC BY-SA 3.0
2017-12-25T21:40:17.053Z
@SajithP chainActive is a variable not a method :) More likely, it's something to do with the makefile, perhaps main.h cannot be included when building -cli instead of the Daemon? Unsure
meshcollider
CC BY-SA 3.0
2017-12-26T02:40:22.560Z
Got it! Then modify the make file to include the object of the class which has the chainActive as a member. e.g 'x.o' where chainActive is a member of class 'x'
SajithP
<bitcoin-core><blockchain><bitcoin-core-development>
Can*t call chainActive.Tip()->nHeight in core.cpp
cgminer-0
# Can*t call chainActive.Tip()->nHeight in core.cpp

(Asked by: username_0 on 2016-06-25)

I want to call chainActive.Tip()->nHeight in core.cpp. It is not possible, I am interested in every idea.

<https://github.com/LIMXTEC/BitSend/blob/DEV-joshafest/src/core.cpp>

Here is an example :

```
bool GetH()
{   
    int nBlockHeight = chainActive.Tip()->nHeight;  
    if(nBlockHeight < FORKX17_Main_Net ) 
        return true;    
    else 
        return false; 
    }
}

uint256 CBlockHeader::GetHash() const 
{   
    if (GetH())     
    {
        return HashX11(BEGIN(nVersion), END(nNonce)); 
    }
    else    
    {
       return HashX17(BEGIN(nVersion), END(nNonce));    
    }
}

```

Also that is not possible:

```
CBlockIndex* pindexPrev = chainActive.Tip();
if (pindexPrev->nHeight <= FORKX17_Main_Net)

```

[![enter image description here](https://i.sstatic.net/EoH5U.jpg)](https://i.sstatic.net/EoH5U.jpg)

**Tags:** bitcoin-core, blockchain, bitcoin-core-development

> **Comments:**
> **username_1**: Looks like you need to `#include "main.h"`?  
> **username_0**: Yes I use main.h. #include "core.h" #include "util.h" #include "main.h" #include "uint256.h"  
> **username_2**: This is due to missing the object of the class which has 'chainActive()' method. So including which ever the file that has the method. In case if it gives further different undefined reference errors; find the file that contains the method; include it; until it compiles ;)  
> **username_3**: @username_2 chainActive is a variable not a method :) More likely, it's something to do with the makefile, perhaps main.h cannot be included when building -cli instead of the Daemon? Unsure  
> **username_2**: Got it! Then modify the make file to include the object of the class which has the chainActive as a member. e.g 'x.o' where chainActive is a member of class 'x'  

---

## 1 answers

### Answer by username_4 on 2018-11-14. Score: 1

As username_2 commented:

> modify the makefile to include the object of the class which has the chainActive as a member. e.g 'x.o' where chainActive is a member of class 'x'


---

