Where should I include rootcint ouput in visual studio2013?

Hello, I tried to use a connect signal of a button having the “missing slot” common error. I read many threads and examples regarding how to bypass the VS linker limitation using rootcint so at the end I:

  • Splitted my class file in header (declaration, C_SerialC.h) and implementation (definition C_SerialC.cpp)
  • made a file LinkDef.h
  • made a bat mainly run rootcint -f dict.Cxx -c C_SerialC.h LinkDef.h

now I tried to #include dict.Cxx before headers, before class definition and after but i always have compiling problems. Where is the mistake?

PS OT: I come from a higher level language so I currently don’t know most of technical details of regarding compiler-linker etc but:
Is theren’t a way to simplify root programming under winzozz? Since root package has its linker and compiler shouldn’t be enough to add a simple text editor correctly linked to root?

Thanks

C_SerialC.h (281 Bytes)
header.h (2.7 KB)
LinkDef.h (153 Bytes)

You need to compile an link the generated dictionary to produce the executable. For example (assuming your source file is called C_SerialC.cxx):

rootcint -f dict.Cxx -c C_SerialC.h LinkDef.h
cl -MD -GR -EHsc -I%ROOTSYS%\include C_SerialC.cxx dict.Cxx /link -LIBPATH:%ROOTSYS%\lib libCore.lib libCint.lib libRIO.lib libNet.lib libHist.lib libGraf.lib libGpad.lib libRint.lib libMatrix.lib libMathCore.lib libGui.lib /out:C_SerialC.exe

Well, ROOT doesn’t have any compiler/linker…

1 Like

Your options give me the error: “Error in TQObject::CheckConnectArgs: slot updateSerialPort() does not exist”

D:\OscilloC\OscilloC>rootcint -f dict.Cxx -c C_SerialC.h LinkDef.h

D:\OscilloC\OscilloC>cl -MD -GR -EHsc -I%ROOTSYSD%\include OscilloC.cpp dict.Cxx /link -LIBPATH:%ROOTSYSD%\lib libCore.lib libCint.lib libRIO.lib libNet.lib libHist.lib libGraf.lib libGpad.lib libRint.lib libMatrix.lib libMathCore.lib libGui.lib /out:OscilloC.exe
Microsoft (R) C/C++ Optimizing Compiler versione 18.00.40629 per x86
Copyright (C) Microsoft Corporation. Tutti i diritti riservati.

OscilloC.cpp
dict.Cxx
Generazione del codice in corso...
Microsoft (R) Incremental Linker Version 12.00.40629.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:OscilloC.exe
-LIBPATH:C:\root_v5.34.36D\lib
libCore.lib
libCint.lib
libRIO.lib
libNet.lib
libHist.lib
libGraf.lib
libGpad.lib
libRint.lib
libMatrix.lib
libMathCore.lib
libGui.lib
/out:OscilloC.exe
OscilloC.obj
dict.obj
   Creazione della libreria OscilloC.lib e dell'oggetto OscilloC.exp in corso...

From the little I understand i compiled both files but i missed where you linked the second to the first.

On the other hand can you explain a little better (or link some documentation) what I should include? Using rootcint i made dict.h and dict.cxx, that must be compiled first and linked explicitly last? **Can you explain me also how to handle it directly in VS without the command line? **

Thanks a lot!

Look for the /link statement in the command line…

And could you provide the necessary files to reproduce the issue? And creating a VS solution for such a little project is an overkill… I’ll come with an explanation nevertheless (even if the command line is much, much simpler)

I read the MS docs regarding cl and the only info i had is that /link override default parameters for linker with defined one, and in the one you defined i didn’t find anything regarding dict.

Here the project, and thanks for help.
OscilloC.zip (20.2 KB)

OK, so here are several things to do:

  • Add rootcint -f dict.Cxx -c C_SerialC.h LinkDef.hin the Pre-Build Event of the Build Events, in the Configuration Properties of your project
  • remove the #include "Windows4Root.h" from header.h
  • Make sure the build type matches the ROOT build type (debug/release), and even if you build in debug mode, link against the release runtime libraries (use the /MD flag instead of /MDd)
  • Enable Run-Time Type Information (/GR)
  • No need to use precompiled headers
  • Add all the headers and all the source in the project
  • Don’t exclude any source file from build
  • In OscilloC.cpp, use #include "C_SerialC.h" instead of #include "C_SerialC.cpp"
  • Finally, in LinkDef.h, replace #ifdef CINT by #ifdef __CINT__
    (I told you that the command line option would be simpler…)
    And let me know if you manage to build it… (it works for me, it just complains: unable to read resistors.csv)

I made what you suggested, here some questions and results:

Why? I need it inside serialC::updateSerialPort(), for now it’s not a problem i commented all code inside the function.

Done, but idk why… I have $(ROOTSYSD) = C:\root_v5.34.36D

I also included #include “header.h” into C_SerialC.cpp

It works perfectly in release mode but in debug mode i have this error

Errore 10 error LNK2019: riferimento al simbolo esterno __imp___CrtDbgReportW non risolto nella funzione "public: bool __thiscall std::_Tree_const_iterator<class std::_Tree_val<struct std::_Tree_simple_types<struct std::pair<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const ,float> > > >::operator==(class std::_Tree_const_iterator<class std::_Tree_val<struct std::_Tree_simple_types<struct std::pair<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const ,float> > > > const &)const " (??8?$_Tree_const_iterator@V?$_Tree_val@U?$_Tree_simple_types@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@M@std@@@std@@@std@@@std@@QBE_NABV01@@Z) D:\OscilloC\OscilloC\OscilloC.obj 1 1 OscilloC

Thanks again bellenot!

ROOT is built in debug mode, but linked with the release runtime libraries

Remove the _DEBUG keyword from the Preprocessor Definitions

You’re very welcome!

1 Like

:blush: all is perfect!

1 Like

I have another question regarding this topic:

I want to close the app when I close the main windows so, as described here so I:

  1. Add customFunctions.h
#ifndef hea
#include "header.h"
#endif
void exit();
  1. Add customFunctions.cpp
#ifndef hea
#include "header.h"
#endif
#include "customFunctions.h"

void exit(){
	gApplication->Terminate(0);
}

  1. Edited main() as follow
...
#include "C_SerialC.h"
#include "customFunctions.h"
int main(int argc, char **argv)
{
	TApplication theApp("TestControlBar", &argc, argv);
	bool run = true;
	TGMainFrame *fMainFrame1847 = new TGMainFrame(gClient->GetRoot(), 10, 10, kMainFrame | kVerticalFrame);
	fMainFrame1847->Connect("CloseWindow()", 0, 0, "exit()");

In the prebuild event i added the new header to have the line

rootcint -f dict.Cxx -c C_SerialC.h customFunctions.h LinkDef.h

I’m having the error “Error in TQObject::CheckConnectArgs: slot exit() does not exist”

Is there something I missed or is there a deeper mistake?

And why not simply like this?:

fMainFrame1847->Connect("CloseWindow()", "TApplication", gApplication, "Terminate()");

You are right, I simplified too much the example. In any case I want to add other code in the exit function; I’m also going to define GUI and interaction directly in the main function so i need a more flexible usage of slots.

Thanks

1 Like

Then you have to generate a dictionary for the functions you want to use in your signal/slots, by adding the declaration in the C_SerialC.h header, and adding the following #pragma in your linkdef.h file

#pragma link C++ function exit;
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.