Linker Error if compiling a simple graph in VS

Hello everyone,

I have copied an easy example to test my root linkage thats been managed through cmake. Cmake did not give me any errors, so I assume the setup worked. However, if I am compiling the following code, VS2019 tells me, it cannot solve “public: __thiscall TCanvas::TCanvas(char const *,char const *,int,int,int,int)”

Code:

#include "TROOT.h"
#include "TCanvas.h"
#include "TFile.h"

using namespace std;

int main(int argc, char* argv[])
{
    TCanvas* canv = new TCanvas("c1", "", 200, 10, 1280, 720);
    TFile* file = new TFile("test.root", "RECREATE");
    file->WriteTObject(canv);

    system("pause");
    return 0;
}

The code highliting does not find anything suspicous, so the libraries seemed to be found. I am compiling as WIN32, as I just read x64 is not currently not supported.


Please read tips for efficient and successful posting and posting code

ROOT Version: 6.18/04
Platform: Windows
Compiler: Visual Studio 2019


You have to link against libGpad.lib (among other libraries…)
And see also this other topic

can this be automated by cmake, maybe even include all libraries?
I have used

target_link_libraries(MainApp PUBLIC ROOT::Graf)

I thought only the crucial ones for graphs will be included, if I use it like this?
I will manually add libGpad.lib and try again.

So you probably have to add Core, RIO (for TFile), and Gpad (for TCanvas), something like:

target_link_libraries(MainApp PUBLIC ROOT::Graf ROOT::Core ROOT::RIO ROOT::Gpad)

And since you don’t create any graphical object, you don’t even need ROOT::Graf

1 Like

Yes, got it to run. Thank you.
However, it seems like root has some problems:

In file included from input_line_3:39:
In file included from C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.24.28314\include\cassert:9:
In file included from C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\assert.h:12:
C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\corecrt.h:142:12: error: redefinition of '_CrtEnableIf<true, _Ty>'
    struct _CrtEnableIf<true, _Ty>
           ^~~~~~~~~~~~~~~~~~~~~~~
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\corecrt.h:142:12: note: previous definition is here
    struct _CrtEnableIf<true, _Ty>
           ^
In file included from input_line_3:39:
In file included from C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.24.28314\include\cassert:9:
In file included from C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\assert.h:12:
C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\corecrt.h:517:16: error: redefinition of '__crt_locale_data_public'
typedef struct __crt_locale_data_public
               ^
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\corecrt.h:516:16: note: previous definition is here
typedef struct __crt_locale_data_public
               ^
In file included from input_line_3:39:
In file included from C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.24.28314\include\cassert:9:
In file included from C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\assert.h:12:
C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\corecrt.h:524:16: error: redefinition of '__crt_locale_pointers'
typedef struct __crt_locale_pointers
               ^
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\corecrt.h:523:16: note: previous definition is here
typedef struct __crt_locale_pointers
               ^
In file included from input_line_3:39:
In file included from C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.24.28314\include\cassert:9:
In file included from C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\assert.h:12:
C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\corecrt.h:532:16: error: redefinition of '_Mbstatet'
typedef struct _Mbstatet
               ^
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\corecrt.h:531:16: note: previous definition is here
typedef struct _Mbstatet
               ^

shall I ignore it?
And if I build root from Git repository, can I make an x64 version out of it, or will it not work at all?

Those errors are due to different versions of Windows 10 SDKs, between the one used to build ROOT (10.0.17763.0) and the one on your system (10.0.18362.0). Try to ignore them, if it doesn’t give any other critical errors, otherwise, you can try to install the version 10.0.17763.0 of the Windows 10 SDK, or rebuild ROOT from source

No need to try, it will not even compile

You can also try one of the nightly build binaries available here, for example root_v6.21.01.win32.vc16.exe

That’s a petty to hear.

I’ve changed my systems SDK to the mentioned 10.0.17763.0, but the error/warning is still appearing:

In file included from input_line_3:39:
In file included from C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.24.28314\include\cassert:9:
In file included from C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\assert.h:12:
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\corecrt.h:142:12: error: redefinition of '_CrtEnableIf<true, _Ty>'
    struct _CrtEnableIf<true, _Ty>
           ^~~~~~~~~~~~~~~~~~~~~~~
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\corecrt.h:142:12: note: previous definition is here
    struct _CrtEnableIf<true, _Ty>
           ^
In file included from input_line_3:39:
In file included from C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.24.28314\include\cassert:9:
In file included from C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\assert.h:12:
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\corecrt.h:516:16: error: redefinition of '__crt_locale_data_public'
typedef struct __crt_locale_data_public
               ^
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.20.27508\include\crtdefs.h:10:10: note: 'C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\corecrt.h' included multiple times, additional include
      site here
#include <corecrt.h>
         ^
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\assert.h:12:10: note: 'C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\corecrt.h' included multiple times, additional include
      site here
#include <corecrt.h>
         ^
In file included from input_line_3:39:
In file included from C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.24.28314\include\cassert:9:
In file included from C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\assert.h:12:
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\corecrt.h:523:16: error: redefinition of '__crt_locale_pointers'
typedef struct __crt_locale_pointers
               ^
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.20.27508\include\crtdefs.h:10:10: note: 'C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\corecrt.h' included multiple times, additional include
      site here
#include <corecrt.h>
         ^
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\assert.h:12:10: note: 'C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\corecrt.h' included multiple times, additional include
      site here
#include <corecrt.h>
         ^
In file included from input_line_3:39:
In file included from C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.24.28314\include\cassert:9:
In file included from C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\assert.h:12:
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\corecrt.h:531:16: error: redefinition of '_Mbstatet'
typedef struct _Mbstatet
               ^
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.20.27508\include\crtdefs.h:10:10: note: 'C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\corecrt.h' included multiple times, additional include
      site here
#include <corecrt.h>
         ^
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\assert.h:12:10: note: 'C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\corecrt.h' included multiple times, additional include
      site here
#include <corecrt.h>

Just to let you know.

OK, so I’m afraid the only solution would be to build from source…

I have cheked the nightly build you recomended. It seems to be brocken (or does not want to cooperate with my system). So I will consider building it, or ignore that error for now. Thank you for patience and help