I compile in VS2017 directly by linking the root binaries. I set the CLR by
Project–> Properties–>General–> Common Language Runtime Support (/clr)
I setup a new VS project with a root “Hello World example”.
It seems that the compilation error message comes via #include"Tfile.h"
/ rootTest.cpp : Defines the entry point for the console application.
//
#include
#include “stdafx.h”
#include “windows4root.h”
#include “TLatex.h”
#include “TCanvas.h”
#include “TPaveTexT.h”
#include “TString.h”
//#include “TFile.h”
#include “TH1F.h”
#include “TH2F.h”
#include
#include “TApplication.h”
#include “TCanvas.h”
#include “TLine.h”
#include “TPaveLabel.h”
int main(int argc, char **argv)
{
TApplication theApp(“App”, &argc, argv);
TCanvas *c = new TCanvas(“c”, “The Hello Canvas”, 400, 400);
TPaveLabel *hello = new TPaveLabel(0.2, 0.4, 0.8, 0.6, “Hello World”);
hello->Draw();
TPaveLabel *quit = new TPaveLabel(0.2, 0.2, 0.8, 0.3, “Close via menu File/Quit”);
quit->Draw();
c->Update();
// Enter event loop, one can now interact with the objects in
// the canvas. Select “Exit ROOT” from Canvas “File” menu to exit
// the event loop and execute the next statements.
theApp.Run(kTRUE);
TLine *l = new TLine(0.1, 0.2, 0.5, 0.9);
l->Draw();
quit->SetLabel(“Select File/Quit again to exit app”);
c->Update();
// Here we don’t return from the eventloop. “Exit ROOT” will quit the app.
theApp.Run();
return 0;
}
if I include TFile I get the error message:
1>------ Build started: Project: rootTest, Configuration: Debug Win32 ------
1>rootTest.cpp
1>c:\root_v6.16.00debug\include\root\libcpp_string_view.h(193): warning C4068: unknown pragma
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.10.25017\include\mutex(8): fatal error C1189: #error: is not supported when compiling with /clr or /clr:pure.
1>Done building project “rootTest.vcxproj” – FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
without TFile it compiles.
I just looked into my TFile.h . I found the include line.
/ @(#)root/io:Id
// Author: Rene Brun 28/11/94
/*************************************************************************
- Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
- All rights reserved. *
-
*
- For the licensing terms see $ROOTSYS/LICENSE. *
- For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/
#ifndef ROOT_TFile
#define ROOT_TFile
//////////////////////////////////////////////////////////////////////////
// //
// TFile //
// //
// ROOT file. //
// //
//////////////////////////////////////////////////////////////////////////
#include
#include “Compression.h”
#include “TDirectoryFile.h”
#include “TMap.h”
#include “TUrl.h”
#include “ROOT/RConcurrentHashColl.hxx”
#ifdef R__USE_IMT
#include “ROOT/TRWSpinLock.hxx”
#include <mutex>
#endif
This explains at least the error-message.
But I am not sure how to avoid. On the web I found advices like:
or