How to compile a c++ file on windows 10 using root and Makefile?

The x86_64 port is ongoing (finally), but since all possible parts of ROOT have to be modified and fundamental changes are needed, it will take some time…

I’ll take a look next month (I’m on sick leave right now)

Thanks bellenot for the instructions. Here is the result. There are 406 warnings and 2 errors at the end:

That’s a weird error. Did you try to configure and build from scratch (i.e. in an empty directory)?

Yes i created a new directory build3 for that purpose and copy/paste your instructions. Since i created a virtual machine from scratch as explained above, may be the installation can be tested with the same conditions by everybody?

Since the error at the end is only the summary, try to find the detailed information in the command prompt history. If you don’t find it, try to rebuild (cmake --build . --config Release) and you might also redirect the output in a file:

cmake --build . --config Release > build-log.txt 2>&1

And search the detailed error in build-log.txt
And as I said, I won’t be able to investigate more until next month

Ok, i will do this and post the resulting file build-log.txt here. Nothing urgent for me, i will wait next month. Take care and thanks a lot.

1 Like

Here is a simple solution to the initial question of this post “How to compile a c++ file on windows 10 using root and Makefile?” explained to me by Alexandre Ratchov.

  1. Suppose that you have Windows 10. (In my case, i installed Windows 10 Pro on a virtual machine on ubuntu 20.04: virt-manager KVM as explained here )
  2. Suppose that the following softwares are installed on windows 10:
  • Visual Studio 2019, version community, with C++ and the package english.
  • cmake
  • Binary version of Root : root_v6.24.00.win32.vc16.exe.
  • If needed you can install other c++ librairies using vcpkg. For example in my case i installed armadillo, boost, gsl, fftw3, by writing .\vcpkg install armadillo, etc
  1. In a directory create a file test.cc that contains
#include <iostream>
#include <TCanvas.h>
#include <TApplication.h>
int main()
{
	TApplication theApp("App", nullptr, nullptr);
	TCanvas *c = new TCanvas("c", "c", 400,400); 
	theApp.Run();
}

and a file Makefile that contains

CPP = cl.exe
CPPFLAGS = /IC:\root_v6.24.00\include
LINK = link.exe
CLIBS = C:\root_v6.24.00\lib

LIBR = $(CLIBS)\libCore.lib $(CLIBS)\libImt.lib $(CLIBS)\libRIO.lib $(CLIBS)\libNet.lib $(CLIBS)\libHist.lib $(CLIBS)\libGraf.lib $(CLIBS)\libGraf3d.lib $(CLIBS)\libGpad.lib $(CLIBS)\libROOTVecOps.lib $(CLIBS)\libTree.lib $(CLIBS)\libTreePlayer.lib $(CLIBS)\libRint.lib $(CLIBS)\libPostscript.lib $(CLIBS)\libMatrix.lib $(CLIBS)\libPhysics.lib $(CLIBS)\libMathCore.lib $(CLIBS)\libThread.lib $(CLIBS)\libROOTDataFrame.lib $(CLIBS)\libGui.lib

test.exe: test.obj
	$(LINK) test.obj $(LIBR)

test.obj: test.cc
	$(CPP) $(CPPFLAGS) -c test.cc

clean:
	-del /q test.obj test.exe
  1. Go to Windows menu/Visual Studio x86 Native Tools Command Prompt to start a terminal. Go to the directory that contains the above files Makefile and test.cc and write nmake to compile. Write test.exe to execute the program.