Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29274 Discussions

How can I call a function in an additional lib (e.g. cernlib)

susi2009
Beginner
3,551 Views
I need to use some functions and subroutines in theCERNLIB. But I could not make it work.
To be specific, for instance, I want to call a function atg(x1,x2), which is in mathlib of the CERNLIB. What I did is:
1) I added "E:\\MathTools\\Cernlib"inProperties->Linker->General->Additional Library Directories
2) I added mathlib.lib, which is in the above quoted directory, in Properties->Linker->Input->Additional Dependencies
3) Then after Build Solution, I got two error messages:
error LNK2019 and fatal error LNK1120

I would appreciate it very much if somebody can tell me the solution. Thanks in advance!
0 Kudos
13 Replies
anthonyrichards
New Contributor III
3,551 Views
What is/are the name(s) of the unresolved externals (LNK1120)? Where do you expect the linker to find them?

Assuming that CERNLIB.LIB is a static library (and not a DLL, so no need for IMPORT directives), why not just include CERNLIB.LIB as a file into your project/solution explicitly first and see if that works?
0 Kudos
susi2009
Beginner
3,551 Views

In fact, I tried. But it didn't work either.

0 Kudos
anthonyrichards
New Contributor III
3,551 Views
Please post the messages in more detail. What CERNLIB functions are you trying to use?
0 Kudos
susi2009
Beginner
3,551 Views
CERNLIB is a fortran library provided by CERN, it contains many .lib files. I had experienceusing CERNLIB incvf.

I want to use MINUIT. For that, I need mathlib.lib, kernlib.lib and packlib.lib which all belong to CERNLIB. I failed. I've checked, the errors werereally due to using functions in
Then I tried a very simple case. As I said in my post, I tried the function atg(x1,x2), which is B101 in elementary functions in CERNLIB.
0 Kudos
Les_Neilson
Valued Contributor II
3,551 Views
Just to check.
Did you compile the cernlib on your system with the IVF compiler or did you download the lib files ?

Les
0 Kudos
susi2009
Beginner
3,551 Views
I just downloaded the lib files.
With cvf, Ijust addedthe lib file into the project, and it worked.
But now, with ivf, no.
0 Kudos
anthonyrichards
New Contributor III
3,551 Views
It looks like you are going to have to download the sources and makefiles and recompile the libraries that you want using IVF if that is the compiler you are now using. I must admit, it looks challenging, not being a command-line user myself and therefore not familiar with makefiles.
0 Kudos
susi2009
Beginner
3,551 Views
Thank you all.
Who can tell me how to compile the libraries? I never did that before
0 Kudos
anthonyrichards
New Contributor III
3,551 Views
If you have never attempted it before, and having looked at the CERNLIB site, It looks a horrible job to attempt from sctratch, since the CERNLIB installation appears to be tailored to UNIX systems and involves loads of Fortran Pre-processing, multiple directories and uses IMAKEFILEs which appear to be defunct and not useable on windows XP systems with modern compilers such as IVF. I would suggest that, if non-linear minimisation/optimisation is what you want, then use the non-linear optimisation functions in the IMSL library that comes with Pro versions of CVF and IVF. Plus the CERNLIB routines are F77 and have not been developed (i.e. no more debugging) for years and can still contain bugs which are not likely to ever be corrected now.
0 Kudos
anthonyrichards
New Contributor III
3,551 Views

Well out of curiosity, I gave it a try and attach a IVF solution for the MINUIT program.
I obtained the MINUITfiles from cernlib\2006\src\packlib\minuit\code and the
test program files MINEXAM and FCNK0 from cernlib\2006\src\packlib\minuit\examples.

The only additional code required wasa version of INTRAC.F that has been taken from
cernlib\2006\src\packlib\kernlib\kerngen\tcgenc,and it has been assumed to be valid
for use on Windows XP Systems (There does not appear to be a special version specifically
recognisable as targeting Windows systems).

I eventually got the MINUIT test program MINEXAM to run under CVF without access violations by making all reals REAL(8) and selecting VMS and F77 compatibilities under project settings, defaulting reals toREAL(8)and extending single precision constants to double etc. (Change details are in the file NEWd506cm.FOR).

I eventually got it to run to completion in debug and release versions and include the results obtained (which appear identical).

I then, from scratch (I did not convert the CVF projects) created an IVF solution for the MINUIT code as a static library and tested it using the MINEXAM test console program , both in release mode, and it ran to completion first time, producing identical output to the CVF program, which was a great relief.

You are welcome to use the code. But judging fromthis experience with MINUIT, there could still be bugs awaiting you in there somewhere!

P.S. I used CVF6.6d and VS2005+IVF 11.1.054

0 Kudos
susi2009
Beginner
3,551 Views
You are great! Thank you very much.
I'll try that. Anyway, MINUIThasbeencommonly used in the community of high energy physics and nuclear physics for many years. So I think the chance to find a bug is tiny...
0 Kudos
anthonyrichards
New Contributor III
3,551 Views
ATG is simple arc tangent function. The source code in cernlib\2006\src\mathlib\gen\gen is

FUNCTION ATG(X1,X2)

PARAMETER (PI = 3.14159 26535 89793D0)

ATG=ATAN2(X1,X2)+(PI-SIGN(PI,X1))
RETURN
END

Note the deliberate omission of specification statements, in whose absence the variables take on their default sizes. You should add them yourself and you can define REAL(4) and REAL(8) versions yourself and just compile them along with your main program code.

You do not need the sledgehammer of the whole of CERNLIB in order to crack this nut!

Beware, the above is a typical example of rubbish code found in many places in CERNLIB.
0 Kudos
anthonyrichards
New Contributor III
3,551 Views

"Anyway, MINUIThasbeencommonly used in the community of high energy physics and nuclear physics for many years. So I think the chance to find a bug is tiny..."

Well, my first try with CVF tripped on a couple!

So the chance may be 'tiny', but it is non-zero. My feelings are aptly summed up in this blog comment I found today: http://mtrr.org/blog/?p=14

...and here is another highly amusing rant against the CERNLIB code: http://www.beowulf.org/archive/2005-October/013985.html

0 Kudos
Reply