Incorporating C++ routines


Jean
07-16-2002, 05:31 PM
Hi

I am a new user of Numerical Recipes and I have some difficulties to run programs from Numerical recipes (Example Book C++) with Visual C++.
Foe example, I tried in vain to run xran.cpp (see below) from the chapter 7:random numbers.

First, I load the Numerical recipes in C++ from the CDROM in my machine.
Second, I create a workspace and a project where
I include a copy of the program xran.cpp .
Third, I modify the 5th line such that the compiler can find the file nr.h .
Fouth, I compile and everything is fine. I built and I obtained some errors.

Could anybody give me some advices?

Thanks


------------Errors----------------

Linking...
xran.obj : error LNK2001: unresolved external symbol "double __cdecl NR::ran3(int &)" (?ran3@NR@@YANAAH@Z)
xran.obj : error LNK2001: unresolved external symbol "double __cdecl NR::ran2(int &)" (?ran2@NR@@YANAAH@Z)
xran.obj : error LNK2001: unresolved external symbol "double __cdecl NR::ran1(int &)" (?ran1@NR@@YANAAH@Z)
xran.obj : error LNK2001: unresolved external symbol "double __cdecl NR::ran0(int &)" (?ran0@NR@@YANAAH@Z)
Debug/Random.exe : fatal error LNK1120: 4 unresolved externals
Error executing link.exe.

-----------xran.cpp---------------

#include <iostream>
#include <iomanip>
#include <cmath>
#include "C:\Program Files\Numerical Recipes\Cpp210\cpp\other\nr.h"

using namespace std;

// Driver for routines ran0, ran1, ran2, ran3

DP fnc(const DP x1, const DP x2, const DP x3, const DP x4)
{
return sqrt(x1*x1+x2*x2+x3*x3+x4*x4);
}

and so on.

rboothby
08-23-2002, 11:54 AM
Jean,

I am having the same problem.

The Microsoft help says the following problem might be happening:

The calling convention (__cdecl, __stdcall, or __fastcall) differs on the use of the function declaration and the function definition.

When I played around with the compiler calling convention options changing them from /Gd to /Gr or /Gz, the error changed to something like this:

CorrDiffVC7 error LNK2019: unresolved external symbol "double __stdcall NR::amotry(class NRMat<double> &,class NRVec<double> &,class NRVec<double> &,double (__stdcall*)(class NRVec<double> const &),int,double)" (?amotry@NR@@YGNAAV?$NRMat@N@@AAV?$NRVec@N@@1P6GNA BV3@@ZHN@Z) referenced in function "void __stdcall NR::amoeba(class NRMat<double> &,class NRVec<double> &,double,double (__stdcall*)(class NRVec<double> const &),int &)" (?amoeba@NR@@YGXAAV?$NRMat@N@@AAV?$NRVec@N@@NP6GNA BV3@@ZAAH@Z)

If anyone has any further ideas, your help would be much appreciated.

Thanks

Rod

Jean
08-23-2002, 04:07 PM
I have worked out what was wrong. It is basic really but when
you don't know how to do it can take a while.

1- I open a project under Win 32 console application
and not Win32 application as I did previously.

2- "I include a copy of the program xran.cpp . "
I create a New Text File under VisualC++ in which I copy-paste my xran program.
Then I just save it as "xran.cpp".
Finally, click (right-hand side button) on "source file" in the tree
, clik on "add files to Folder" and select "xran.cpp".


Jean