# Can't compile a ROOT 6 macro on Windows 10

**URL:** <https://root-forum.cern.ch/t/cant-compile-a-root-6-macro-on-windows-10/55174>\
**Category:** Newbie\
**Tags:** root\
**Created:** [June 4, 2023, 9:59pm UTC](https://root-forum.cern.ch/t/cant-compile-a-root-6-macro-on-windows-10/55174 "2023-06-04T21:59:06Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![N-Kulagin](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/n-kulagin/32/33529_2.png) [@N-Kulagin](https://root-forum.cern.ch/u/N-Kulagin)\
**Post date:** [June 4, 2023, 9:59pm UTC](https://root-forum.cern.ch/t/cant-compile-a-root-6-macro-on-windows-10/55174/1 "2023-06-04T21:59:06Z")

</div>

So I can’t quite figure out how to compile my code on Windows 10. I installed root using the latest .exe installer for windows and installed it into directory `D:\ROOT\root_v6.28.04`, since there was some problem for ROOT with adding itself to PATH (“path variable is too long”) I had to manually add the root\_v6.28.04, bin and macro folders to PATH, then just ran a visual studio code inside macro folder and used root inside the built-in terminal of VS code.

I know my macro runs well using root’s C++ interpreter (it just draws some 2D gaussian distribution), however when I try to compile the code using `root histogram_2D.cpp+` it returns this code which I don’t know how to interpret:

```auto
root [0] 
Processing histogram_2D.cpp+...
Info in <TWinNTSystem::ACLiC>: creating shared library D:/ROOT/root_v6.28.04/macros/histogram_2D_cpp.dll

==========================================
=============== STACKTRACE ===============
==========================================

================ Thread 0 ================
  libCore!TWinNTSystem::DispatchSignals()
  ucrtbase!seh_filter_exe()
  root!Init_thread_header()
  VCRUNTIME140!_C_specific_handler()
  ntdll!_chkstk()
  ntdll!RtlRaiseException()
  ntdll!KiUserExceptionDispatcher()
  libCore!TWinNTSystem::GetLibraries()
  libCore!TSystem::CompileMacro()
  libCling!TCling::ProcessLine()
  libCling!TCling::ProcessLineSynch()
  libCore!TApplication::ExecuteFile()
  libCore!TApplication::ProcessLine()
  libRint!TRint::ProcessLineNr()
  libRint!TRint::Run()
  root!??
  root!??
  KERNEL32!BaseThreadInitThunk()
  ntdll!RtlUserThreadStart()

================ Thread 1 ================
  ntdll!NtWaitForWorkViaWorkerFactory()
  ntdll!RtlInitializeResource()
  KERNEL32!BaseThreadInitThunk()
  ntdll!RtlUserThreadStart()

================ Thread 2 ================
  ntdll!NtWaitForWorkViaWorkerFactory()
  ntdll!RtlInitializeResource()
  KERNEL32!BaseThreadInitThunk()
  ntdll!RtlUserThreadStart()

================ Thread 3 ================
  ntdll!NtWaitForWorkViaWorkerFactory()
  ntdll!RtlInitializeResource()
  KERNEL32!BaseThreadInitThunk()
  ntdll!RtlUserThreadStart()

================ Thread 4 ================
  ntdll!NtDelayExecution()
  KERNELBASE!SleepEx()
  libCore!TWinNTSystem::TimerThread()
  libCore!TWinNTSystem::ThreadStub()
  KERNEL32!BaseThreadInitThunk()
  ntdll!RtlUserThreadStart()

================ Thread 5 ================
  win32u!NtUserGetMessage()
  USER32!GetMessageA()
  libCore!TWinNTSystem::FreeDirectory()
  KERNEL32!BaseThreadInitThunk()
  ntdll!RtlUserThreadStart()

==========================================
============= END STACKTRACE =============
==========================================

```

Nothing is being shown/drawn unlike just running it normally, the library `histogram_2D_cpp.dll` isn’t even being created too. It seems like I installed gcc/g++ in my system, but the problem persists. Do I need to rename my function from `void histogram_2D()` to `int main()`? (It didn’t help when I did). I have all the required ROOT classes included in my program, so that shouldn’t be a problem. Honeslty I’m not even sure what output of a compilation should I expect? An exe file or perhaps something else? There’s a bunch being created in my macro folder like `.d`, `.rootmap`, `ACLiC_map.in`, etc.

I know visual studio code doesn’t come with a compiler by default, but is there a way to still compile my C++ code, while editing it in VS code? I really don’t want to use visual studio because it creates a bunch of extra files and folders I don’t need in my macros folder.

_ROOT Version:_ 6.28.04  
_Platform:_ Windows 10  
_Compiler:_ Not Provided

* * *

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [June 5, 2023, 6:46am UTC](https://root-forum.cern.ch/t/cant-compile-a-root-6-macro-on-windows-10/55174/2 "2023-06-05T06:46:07Z")

</div>

In order to use ACLiC, you must be in a Visual Studio environment, i.e. in a `x64 Native Tools Command Prompt for VS 2022`

---

<div class="post-metadata">

**Author:** ![N-Kulagin](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/n-kulagin/32/33529_2.png) [@N-Kulagin](https://root-forum.cern.ch/u/N-Kulagin)\
**Post date:** [June 6, 2023, 1:46am UTC](https://root-forum.cern.ch/t/cant-compile-a-root-6-macro-on-windows-10/55174/3 "2023-06-06T01:46:39Z")

</div>

Is there a way to make that work outside of visual studio? I can launch the command prompt as an admin, but when I try to compile it there I’m getting this error:  
`D:\ROOT\root_v6.28.04\macros\histogram_2D_cpp_ACLiC_dict.cxx(7): fatal error C1083: Can't open include file: stddef.h: No such file or directory`

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [June 6, 2023, 6:54am UTC](https://root-forum.cern.ch/t/cant-compile-a-root-6-macro-on-windows-10/55174/4 "2023-06-06T06:54:01Z")

</div>

> [@N-Kulagin](#):
>
> Is there a way to make that work outside of visual studio?

Yes, as I said, open a `x64 Native Tools Command Prompt for VS 2022` (or a `x86 Native Tools Command Prompt for VS 2022` for 32 bit) and run from there

---

<div class="post-metadata">

**Author:** ![N-Kulagin](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/n-kulagin/32/33529_2.png) [@N-Kulagin](https://root-forum.cern.ch/u/N-Kulagin)\
**Post date:** [June 6, 2023, 7:18am UTC](https://root-forum.cern.ch/t/cant-compile-a-root-6-macro-on-windows-10/55174/5 "2023-06-06T07:18:40Z")

</div>

That’s what I did and I get an error described in my previous comment.

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [June 6, 2023, 7:30am UTC](https://root-forum.cern.ch/t/cant-compile-a-root-6-macro-on-windows-10/55174/6 "2023-06-06T07:30:20Z")

</div>

Did you install the `Desktop development with C++` component of Visual Studio?

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [June 6, 2023, 7:42am UTC](https://root-forum.cern.ch/t/cant-compile-a-root-6-macro-on-windows-10/55174/7 "2023-06-06T07:42:16Z")

</div>

[ROOT → Blog Posts → How to run ROOT Macros in VS Code](https://root.cern/blog/root-on-vscode/)

---

<div class="post-metadata">

**Author:** ![N-Kulagin](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/n-kulagin/32/33529_2.png) [@N-Kulagin](https://root-forum.cern.ch/u/N-Kulagin)\
**Post date:** [June 6, 2023, 8:34am UTC](https://root-forum.cern.ch/t/cant-compile-a-root-6-macro-on-windows-10/55174/8 "2023-06-06T08:34:00Z")

</div>

Yep I did, last month I reinstalled VS to get the new VS 2022 and now checked again that I have that component installed.

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [June 6, 2023, 8:51am UTC](https://root-forum.cern.ch/t/cant-compile-a-root-6-macro-on-windows-10/55174/9 "2023-06-06T08:51:20Z")

</div>

Can you share your `histogram_2D.cpp` file?

---

<div class="post-metadata">

**Author:** ![N-Kulagin](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/n-kulagin/32/33529_2.png) [@N-Kulagin](https://root-forum.cern.ch/u/N-Kulagin)\
**Post date:** [June 6, 2023, 9:07am UTC](https://root-forum.cern.ch/t/cant-compile-a-root-6-macro-on-windows-10/55174/10 "2023-06-06T09:07:02Z")

</div>

Here it is. I temporarily commented out the `gStyle` because I’m not sure how to make it recognizeable by VS Code and stop compilation errors that whine about it being undefined, but that’s not the main problem here.

```auto
#include <iostream>
#include <TCanvas.h>
#include <TRandom2.h>
#include <TH2F.h>

void histogram_2D(double num_points = 1e7, bool enable_rainbow = 0){

    if (num_points < 0){
        std::cout << std::endl;
        std::cout << "---------------------------------------------------" << std::endl;
        std::cout << "Exception! Number of points should be non-negative" << std::endl;
        std::cout << "---------------------------------------------------" << std::endl;
        throw 1;
    }
    int maximum = num_points;

    TCanvas* c = new TCanvas();
    c->SetTicks();

    if (enable_rainbow){
        std::cout << enable_rainbow;
        //gStyle->SetPalette(kRainBow);
    }

    TH2F* hist = new TH2F("hist","2D Histogram",300,-25,25,300,-25,25);
    hist->SetStats(0);
    hist->SetAxisColor(kRed,"Y");
    hist->SetXTitle("X axis");
    hist->SetYTitle("Y axis");
    hist->SetTickLength(0.05,"Y");
    hist->SetContour(1000);

    TRandom2* rnd = new TRandom2();

    for (size_t i = 0; i < maximum; ++i)
    {
        double x = rnd->Gaus(0,0.4);
        double y = rnd->Gaus(-1,1.5);
        hist->Fill(-10*x-4*y,4*y);
    }
    
    hist->Draw("colz");

    c->Print("histogram_2D_1.pdf");
}

```

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [June 6, 2023, 9:10am UTC](https://root-forum.cern.ch/t/cant-compile-a-root-6-macro-on-windows-10/55174/11 "2023-06-06T09:10:09Z")

</div>

I don’t see any problem with your code:

```auto
**********************************************************************
** Visual Studio 2022 Developer Command Prompt v17.6.2
** Copyright (c) 2022 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x64'

C:\Users\bellenot>cd \root-dev

C:\root-dev>build\x64\release\bin\thisroot.bat

C:\root-dev>root -l histogram_2D.cpp++
root [0]
Processing histogram_2D.cpp++...
Info in <TWinNTSystem::ACLiC>: creating shared library C:/root-dev/histogram_2D_cpp.dll
histogram_2D_cpp_ACLiC_dict.cxx
   Creating library C:/root-dev\histogram_2D_cpp.lib and object C:/root-dev\histogram_2D_cpp.exp
histogram_2D_cpp_ACLiC_dict.cxx
   Creating library C:/root-dev\histogram_2D_cpp.lib and object C:/root-dev\histogram_2D_cpp.exp
Info in <TCanvas::Print>: pdf file histogram_2D_1.pdf has been created
root [1]

```
