How can I import CLASSES from .DLL by external compiler?

Hi there,
I am a beginner in ROOT and VC++.
How can I import classes like TStopwatch or TComplex from .dll libraries of ROOT
using VC++ 8.0 environment?
I need this to build .exe file of the project to speed up the calculation.
When I tried to use method with FARPROC pointer the message that TStopwatch is not a class or namespace appears.
Was these DLLs compiled without __declspec() options to classes?
Is the only way to compile the ROOT project with classes support under Windows to use Cygwin?
Where can I find the detailed instruction on how to do this?

Thanks a lot for future reply.

Hi,

I’m not sure to really understand your problem, but you must link with the .lib files (i.e. add the libraries in the input field of the linker options of your project). If you don’t know how to proceed, just post a zip file with your project, and I will correct it.

Cheers,
Bertrand.

[quote=“bellenot”]Hi,

I’m not sure to really understand your problem, but you must link with the .lib files (i.e. add the libraries in the input field of the linker options of your project). If you don’t know how to proceed, just post a zip file with your project, and I will correct it.

Cheers,
Bertrand.[/quote]

I have done this but with the same result. In this case I can use without any problem functions from .DLLs but can not use classes like TComplex or TStopwatch.

With best regards.

Which Root libraries are you linking with your application ?
Can you post your application to allow me to take a look ?

– Bertrand.

[quote=“bellenot”]Which Root libraries are you linking with your application ?
Can you post your application to allow me to take a look ?

– Bertrand.[/quote]

Here is my simple source file and the project without .ncb file.
This is version with FARPROC pointer.

The error message
1>------ Build started: Project: tot, Configuration: Debug Win32 ------
1>Compiling…
1>Totpr.cpp
1>c:\begun\totpr.cpp(46) : error C2653: ‘TStopwatch’ : is not a class or namespace name
1>c:\begun\totpr.cpp(46) : error C2645: no qualified name for pointer to member (found ‘:: *’)
1>c:\begun\totpr.cpp(46) : fatal error C1903: unable to recover from previous error(s); stopping compilation
1>Build log was saved at “file://c:\Begun\tot\tot\Debug\BuildLog.htm”
1>tot - 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
tot.zip (88.5 KB)
Totpr.cpp (1.81 KB)

First of all, you have to include the declaration of TStopWatch in your code (i.e. #include “c:\root\include\TStopWatch.h”)
But the compilation will still fail with unresolved externals, since you have to link against ROOT libs…
And this code: HINSTANCE fl5=LoadLibrary("c:\\root\\bin\\libCore.dll"); GetProcAddress(fl5, "Constructor");
Cannot work - how the system can guess which constructor has to be called ? is there any exported function called “Constructor” in libCore.dll ? I don’t think so…
Why not using the standard way of linking (with libCore.lib) ? do you really need to dynamically load the DLLs ?
– Bertrand.

[quote=“bellenot”]First of all, you have to include the declaration of TStopWatch in your code (i.e. #include “c:\root\include\TStopWatch.h”)
But the compilation will still fail with unresolved externals, since you have to link against ROOT libs…
And this code: HINSTANCE fl5=LoadLibrary("c:\\root\\bin\\libCore.dll"); GetProcAddress(fl5, "Constructor");
Cannot work - how the system can guess which constructor has to be called ? is there any exported function called “Constructor” in libCore.dll ? I don’t think so…
Why not using the standard way of linking (with libCore.lib) ? do you really need to dynamically load the DLLs ?
– Bertrand.[/quote]

When I link corresponding ROOT libs (.lib files) I CAN NOT USE CLASSES like TComplex and TStopwatch.

Please take a look at the attached project. It uses TStopWatch and TComplex. There is no problem at all…
tot.zip (5.51 KB)

Thank you. Timer is working now.

What about TComplex class I think that the secret was in following strings

     double x=last_histo->GetXaxis()->GetBinCenter(bx);
     double y=last_histo->GetYaxis()->GetBinCenter(by);
     TComplex point( x,y);
     TComplex z=point;

I suppose that this works like some kind of redefinition of class TComplex.
I have thought before that including of TComplex and declaration of variable like

TComplex z;

is just enough. But such declaration leads to error in VC++ 8.0 environment.

There is no problem declaring a variable like TComplex z;
To try, just modify Totpr.cpp as following:

int main() { TComplex a; const int max_iter=50; [...] if(iter>max_iter) break; } a = TComplex::Sqrt(z); } [...]
You will see it works…
Bertrand.

[quote=“bellenot”]There is no problem declaring a variable like TComplex z;
To try, just modify Totpr.cpp as following:

int main() { TComplex a; const int max_iter=50; [...] if(iter>max_iter) break; } a = TComplex::Sqrt(z); } [...]
You will see it works…
Bertrand.[/quote]

Thank you.
I have understood. My problem was in the way of initialization I should did this like

TComplex z=z(x,y);

No. It should be this way:

TComplex z(x,y);

Cheers, Bertrand.

[quote=“bellenot”]No. It should be this way:

TComplex z(x,y);

Cheers, Bertrand.[/quote]

I have used variant

TComplex z;

Double_t x=4.0, y=4.0;

z=z(x,y);

It works too.

[quote=“bellenot”]First of all, you have to include the declaration of TStopWatch in your code (i.e. #include “c:\root\include\TStopWatch.h”)
But the compilation will still fail with unresolved externals, since you have to link against ROOT libs…
And this code: HINSTANCE fl5=LoadLibrary("c:\\root\\bin\\libCore.dll"); GetProcAddress(fl5, "Constructor");
Cannot work - how the system can guess which constructor has to be called ? is there any exported function called “Constructor” in libCore.dll ? I don’t think so…
Why not using the standard way of linking (with libCore.lib) ? do you really need to dynamically load the DLLs ?
– Bertrand.[/quote]

Hello,
the word “Constructor” is there ??0TComplex@@QAE@XZ
or there ??0TStopwatch@@QAE@XZ for TStopwatch
But if I have .lib file the best way is to use it.

Thank you for advice.

Cheers, Sergij

[quote=“SBegun”]Hi there,
I am a beginner in ROOT and VC++.
How can I import classes like TStopwatch or TComplex from .dll libraries of ROOT
using VC++ 8.0 environment?
I need this to build .exe file of the project to speed up the calculation.
When I tried to use method with FARPROC pointer the message that TStopwatch is not a class or namespace appears.
Was these DLLs compiled without __declspec() options to classes?
Is the only way to compile the ROOT project with classes support under Windows to use Cygwin?
Where can I find the detailed instruction on how to do this?

Thanks a lot for future reply.[/quote]Did you try ACliC? (see: ftp://root.cern.ch/root/doc/7CINT.pdf page 93)

[quote=“fine”][quote=“SBegun”]Hi there,
I am a beginner in ROOT and VC++.
How can I import classes like TStopwatch or TComplex from .dll libraries of ROOT
using VC++ 8.0 environment?
I need this to build .exe file of the project to speed up the calculation.
When I tried to use method with FARPROC pointer the message that TStopwatch is not a class or namespace appears.
Was these DLLs compiled without __declspec() options to classes?
Is the only way to compile the ROOT project with classes support under Windows to use Cygwin?
Where can I find the detailed instruction on how to do this?

Thanks a lot for future reply.[/quote]Did you try ACliC? (see: ftp://root.cern.ch/root/doc/7CINT.pdf page 93)[/quote]

Hello,
I am working under Windows XP thus the .so files is not fit.
There is no other way to use Classes from .DLLs of ROOT as to include (link) corresponding .LIB files of ROOT under creation of object code file .OBJ and under creation of executable file .EXE.

Cheers, Sergij

Sergij,

FYI, ACliC works also on Windows (just replace .so by .dll)…

Cheers,
Bertrand.

[quote=“bellenot”]Sergij,

FYI, ACliC works also on Windows (just replace .so by .dll)…

Cheers,
Bertrand.[/quote]

Thank you.

But when I have tried to make .dll from Totpr.cpp by .L Totpr.cpp+ in CINT
The error appears

root [20] .L Totpr.cpp++
Info in TWinNTSystem::ACLiC: creating shared library c:\root\Totpr_cpp.dll
’cl’ is not recognized as an internal or external command,
operable program or batch file.
Error: external preprocessing failed. (0)
!!!Removing c:\root\s340_1n.cxx c:\root\s340_1n.h !!!
Error: rootcint: error loading headers…
Error in : Dictionary generation failed!
Info in : Invoking compiler to check macro’s validity
’cl’ is not recognized as an internal or external command,
operable program or batch file.
root [21]

What is wrong?

Thank you for future reply.

As I told you before, your PATH must contain (at least) the path to cl.exe (C:\Program Files\Microsoft Visual Studio 8\VC\bin)

Cheers,
Bertrand.

[quote=“bellenot”]As I told you before, your PATH must contain (at least) the path to cl.exe (C:\Program Files\Microsoft Visual Studio 8\VC\bin)

Cheers,
Bertrand.[/quote]

What the name should I assign with this path in system.rootrc?
Or where should I include this pathname?

Thank you for future reply.