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

In the “command prompt”, you probably need:

cd \...\test
..\bin\thisroot.bat
nmake /f Makefile.win32

The command nmake /f Makefile.win32 gives:

Makefile.win32(66) : fatal error U1052: fichier 'win32.mak' introuvable
Stop.

I found in this post that win32.mak is provided by Windows SDK. So i have installed windows SDK and re-installed Visual Studio so that he may find win32.mak. But still i have the same error. Somebody has an idea?

PS: My computer is a recent XPS13 (64 bits), so i am surprised to need win32. I am using Windows 10 on a virtual machine under ubuntu 20.04: virt-manager KVM as explained here. My objective is to export some c++ project that uses root from linux, to the Windows 10 platform.

I don’t use Windows myself (all I remember was once valid for ROOT 5, which was indeed a 32-bit x86 application).

You can use CMake, or you can compile in the command prompt, for example:

cl -nologo -O2 -MD -GR -EHsc -I%ROOTSYS%\include mysource.cxx /link -LIBPATH:%ROOTSYS%\lib libCore.lib libGui.lib libGpad.lib libHist.lib libTree.lib libGraf.lib /out:myapplication.exe 

or change the following lines in Makefile.win32:

!if ([nmake /? 2>&1 | findstr /c:"Version 11\." > nul ] == 0) || \
    ([nmake /? 2>&1 | findstr /c:"Version 12\." > nul ] == 0)
APPVER    = 5.01
cc        = cl
link      = link
implib    = lib
lflags    = $(lflags) /INCREMENTAL:NO /NOLOGO
DLLENTRY  = @12
conlflags = $(lflags) -subsystem:console
guilflags = $(lflags) -subsystem:windows
dlllflags = $(lflags) -entry:_DllMainCRTStartup$(DLLENTRY) -dll
!else
!include <win32.mak>
!endif

as:

APPVER    = 5.01
cc        = cl
link      = link
implib    = lib
lflags    = $(lflags) /INCREMENTAL:NO /NOLOGO
DLLENTRY  = @12
conlflags = $(lflags) -subsystem:console
guilflags = $(lflags) -subsystem:windows
dlllflags = $(lflags) -entry:_DllMainCRTStartup$(DLLENTRY) -dll

@bellenot Can you fix all Makefile.win32 files (and the Makefile.arch, if needed) in the official source code repository?

Actually, they should be “.win64” now, or may better “.mvc”. Keeping “.win32” may be misleading.

Update: The 23rd post here says that ROOT 6 is still a 32-bit x86 application (even on 64-bit Windows), so “.win32” is “mandatory”.

Will do, once back at work (next month). And win32.mak is obsolete

Hello, thanks for the information.
So i tried to compile hsimple.cxx or guitest.cxx like this:


The error is a missing librairy. So i checked which librairies are in directory lib:
image

So it seems that many lib are missing here? Do you have an idea?

How did you install ROOT?

What i did from the begining:

  1. On ubuntu 20.04: i installed Windows 10 Pro on a virtual machine virt-manager KVM as explained here
  2. On this windows 10 virtual machine, i installed Visual Studio community and CMake and Windows SDK and GitHub.
  3. From github, i downloaded root
  4. I followed more or less the file INSTALL and did in the directory root-master:
mkdir build2
cd build2
cmake ../root-master -Dclad=OFF
cmake --build .

Then the previous message shows what i did in the directory test.

Why -Dclad=OFF? Here is the correct configuration:

cmake -G"Visual Studio 16 2019" -A Win32 -Thost=x64 -DCMAKE_VERBOSE_MAKEFILE=ON ../root-master 

This is not enough. On Windows you must specify the configuration (e.g. Debug or Release):

cmake --build . --config Release

And make sure you run in a x86 Native Tools Command Prompt for VS 2019.
Please try again and check if there is any error message at the end of the build

@bellenot Why are these MANDATORY additional flags missing in the official instructions on the “Installing ROOT” and “Building ROOT from source” web pages?

Well, you’re right, the Windows specific part is missing…

There is one thing that I don’t understand now. Is ROOT 6 built with MVC on Windows still only a 32-bit x86 application, or can it be built as a proper 64-bit x86_64 one?

BTW. The "-Dclad=OFF is a result of an error shown in the 7th post here. Maybe you know how to fix it.

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.