Problem when compiling

Hi
i am running root 5.30/00 on windows 7. when i try to make a shared libary from a simple test case

// Datei: easyTest.c
void easyTest(){
}

i get the following error:

root [0] .L easyTest.c+
Info in <TWinNTSystem::ACLiC>: creating shared library C:\root\work\easyTest_c.dll
Der Befehl "cl.exe" ist entweder falsch geschrieben oder
konnte nicht gefunden werden.
Error: external preprocessing failed. (0)
!!!Removing C:\root\work\easyTest_c_ACLiC_dict.cxx C:\root\work\easyTest_c_ACLiC_dict.h !!!
Error: C:\root\bin\rootcint: error loading headers...
Error in <ACLiC>: Dictionary generation failed!
Info in <ACLiC>: Invoking compiler to check macro's validity
Der Befehl "cl" ist entweder falsch geschrieben oder
konnte nicht gefunden werden.
root [1]

the same message i get when i want to create a shared lib from any other file.
would be nice if someone could help me…

Hi,

To use ACLiC, you need Visual Studio (Visual C++). If it is already installed on you system, you have to run the batch script used to set the environment variables needed by the compiler (e.g. C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\vcvars32.bat) from the command prompt before to start root (or start the visual studio command prompt from the “Visual Studio Tools” menu).

Cheers, Bertrand.

Hi
I found lots of hits with the same problem but this batch seems to have different names on different version. Looking at the porperties of the VCs command promt i could figure out the correct name.
thx alot for the answer.

Oh yes, sorry, I forgot to mention this :blush: Depends on the version of Visual Studio, and if Windows is 32 or 64 bit…
Cheers, Bertrand.

i dont want to start a new post, so i just continue this one…

i am a bit confused about some include statements in my code and im not sure what is the way to create a shared lib in this case… i tried to boil it down to a simple example:

i have a main program (Main.C) that calls a function from another file and works with 2 classes defined in seperate files

#include "Class1.C"
#include "Class2.C"
#include "anc.c"

void main(){
    Class1* c = new Class1();
    Class2* d = c->returnClass2();
    d->callExternal();
    externalFunc();
}

this is class1 header (Class1.h):

#ifndef Class1_h
#define Class1_h
#include "Class2.C"
#include <iostream>
class Class1 {
public :
   Class1(); 
   virtual Class2* returnClass2();
};
#endif
#ifdef Class1_cxx 
Class1::Class1(){
    cout << "class1 constr" << endl;
}
#endif [/code]
and its source (Class1.C)
[code]#define Class1_cxx
#include "Class1.h"
Class2* Class1::returnClass2(){
   Class2* c = new Class2();   
   return c;
}[/code]
and the second class (Class2.h)
[code]#ifndef Class2_h
#define Class2_h

#include <iostream>
#include "anc.c"

class Class2 {
public :
   Class2();
   virtual void callExternal();
};
#endif

#ifdef Class2_cxx
Class2::Class2(){
    cout << "class2 constr" << endl;
}
#endif 

and (Class2.C)

#define Class2_cxx
#include "Class2.h"
#include "anc.c"
#include <iostream>
void Class2::callExternal(){
    externalFunc();
}

and the file with the “external” function (anc.c)

#include <iostream>
void externalFunc(){
    cout << "ext test" << endl;
}

when i run this in root, i get what i would expect:

root [0] .L Main.C
root [1] main()
class1 constr
class2 constr
ext test
ext test

however, when i try to make shared libs before calling the methods, it always ends up in a mess.
e.g. i tried to run the following skript

{ gROOT->ProcessLine(".L Class1.C+"); gROOT->ProcessLine(".L Class2.C+"); gROOT->ProcessLine(".L anc.c+"); gROOT->ProcessLine(".L Main.C"); }
but this results in lots of error messages…(i dont post them here since this is only one of many possible ways i tried and it is definitely a wrong one).

What do i have to include where ? And how do i create a shared library that i can call from the main program? How do i include this lib in the main program ?

Hi,

First of all, as this is not related to the previous post, you should have started a new thread.
Then you should not include source files (.C) in header files (.h), and use forward declarations… Do you have some experience with C++?
Anyway, here is a possible solution (but not very elegant…):
Main.C:[code]#include “Class1.C”
#include “Class2.C”
#include “anc.c”

void main(){
Class1* c = new Class1();
Class2* d = c->returnClass2();
d->callExternal();
externalFunc();
}
[/code]
Class1.h:[code]#ifndef Class1_h
#define Class1_h

#include

class Class2;

class Class1 {
public :
Class1();
virtual Class2* returnClass2();
};

#endif[/code]
Class1.C:[code]#include “Class1.h”
#include “Class2.h”

Class1::Class1(){
cout << “class1 constr” << endl;
}

Class2* Class1::returnClass2(){
Class2* c = new Class2();
return c;
}[/code]
Class2.h:[code]#ifndef Class2_h
#define Class2_h

class Class2 {
public :
Class2();
virtual void callExternal();
};

#endif[/code]
Class2.C:[code]#include "Class2.h"
extern void externalFunc();

Class2::Class2(){
cout << “class2 constr” << endl;
}

void Class2::callExternal(){
externalFunc();
}[/code]
anc.c:[code]#include

void externalFunc(){
cout << “ext test” << endl;
}[/code]
But you can also use one single source file and one (or more) header file(s)…
Header file:[code]#ifndef MyHeader_h
#define MyHeader_h

#include

class Class2 {
public :
Class2();
virtual void callExternal();
};

class Class1 {
public :
Class1();
virtual Class2* returnClass2();
};

#endif[/code]
Single source file:[code]#include “MyHeader.h”

void externalFunc(){
cout << “ext test” << endl;
}

Class1::Class1(){
cout << “class1 constr” << endl;
}

Class2* Class1::returnClass2(){
Class2* c = new Class2();
return c;
}

Class2::Class2(){
cout << “class2 constr” << endl;
}

void Class2::callExternal(){
externalFunc();
}

void main(){
Class1* c = new Class1();
Class2* d = c->returnClass2();
d->callExternal();
externalFunc();
}
[/code]
Or any intermediate solution…

Cheers, Bertrand.

[quote]
First of all, as this is not related to the previous post, you should have started a new thread.[/quote]

maybe yes…

some yes, but unfortunately not soo much :wink:

thx a lot for your fast and clear answer.