How to use Bessel function in a code compiled with ACLIC

I want to use the Bessel function in a code.The code given below is working with root -l t1.C but not working with root -l t1.C+. It shows an error : “error: ‘ROOT::Math’ has not been declared”.

#include <iostream>
#include <TMath.h>
#include <TSystem.h> 

//#include "Math/MathMore.h"

using namespace std;

void t1(){
	gSystem->Load("libMathMore");
	


	cout<<"cyl_bessel_k(2,0.001) = "<<ROOT::Math::cyl_bessel_k(2,0.001)<<endl;
//cout<<"cyl_bessel_k(1,0.001) = "<<ROOT::Math::cyl_bessel_k(1,0.001)<<endl;
//cout<<"cyl_bessel_k(3,0.001) = "<<ROOT::Math::cyl_bessel_k(3,0.001)<<endl;

	
}

Thanks

When using ACLiC, you need to add missing includes for the libraries you use. Try uncommenting the #include directive that you have in your macro. It may work once you include the right header.

Could you please try as shown below? It works for me.

#include <iostream>

#include "Math/SpecFunc.h"
#include "TSystem.h"

void bessel()
{
   gSystem->Load("libMathMore");

	std::cout << "cyl_bessel_k(2,0.001) = "<< ROOT::Math::cyl_bessel_k(2,0.001) << endl;
}
epsft-53 root $ root -q -l bessel.C+

Processing bessel.C+...
cyl_bessel_k(2,0.001) = 2e+06

Thanks for your reply. Unfortunately, it is still showing error:

bessel_C_ACLiC_dict.cxx:(.text+0x3a): undefined reference to `ROOT::Math::cyl_bessel_k(double, double)'
collect2: error: ld returned 1 exit status
Error in : Compilation failed!
Error: Function bessel() is not defined in current scope :0:
*** Interpreter error recovered ***

Can you please tell me the header file required to use mathmore? “Math/MathMore.h” is not the correct header.

Thanks.

The header is Math/SpecFunc.h. If you don’t have that header, you may not have GSL installed or ROOT is not installed with -Dmathmore=ON. In any case, your error is that function bessel() was not found, so you probably just need to name the macro bessel.C for it to work for you. The function ROOT tries to run is always the name of the macro without the extension.

Macro is working normally:
root -l bessel.C
root [0]
Processing bessel.C…
cyl_bessel_k(2,0.001) = 2e+06

So I think mathmore is on. Also I have checked that ‘SpecFuncMathMore.h’ is there in the directory ‘/math/mathmore/inc/Math/’.
Problem is that, it shows error when I am compiling it with ACLIC:
Processing bessel.C+…
Info in TUnixSystem::ACLiC: creating shared library /./bessel_C.so
/bessel_C_ACLiC_dict.o: In function bessel()': bessel_C_ACLiC_dict.cxx:(.text+0x3a): undefined reference toROOT::Math::cyl_bessel_k(double, double)’
collect2: error: ld returned 1 exit status
Error in : Compilation failed!
Error: Function bessel() is not defined in current scope :0:
*** Interpreter error recovered ***

The macro is attcahed here.bessel.C (246 Bytes)

Thank you very much.

It’s an unresolved symbol - i.e. a linker error. You’ll need to link against the library containing ROOT::Math::cyl_bessel_k(double, double) which is in libMathMore. Interactive ROOT is smart enough to load that library automatically.

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