Why I cannot link?


dddavid
07-10-2003, 09:39 PM
I want to test "svd" algorithm in NR, so I use the example --"xsvdcmp.c" . I can compile it ,but I cannot link. When linking, I got errors:
error LNK2001: unresolved external symbol "void __cdecl free_vector(float *,long,long)" (?free_vector@@YAXPAMJJ@Z)
etc.

what's wrong?

dddavid
07-10-2003, 10:52 PM
for simple,I can show another example
#include <iostream.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define NRANSI
#include "nr.h"
#include "nrutil.h"
int main(int argc, char* argv[])
{
int i,j;
float **a;


a=matrix(1,3,1,3);

for( i = 1; i <= 3 ; i++)
{
for (j=1;j<=3;j++)
a[i][j]=(float)((i-1)*3 + j);
}
cout << a[1][1] << endl;
return 0;
}
#undef NRANSI

It can be compiled,but when linking,it gives errors:
error LNK2001: unresolved external symbol "float * * __cdecl matrix(long,long,long,long)" (?matrix@@YAPAPAMJJJJ@Z)
Debug/testsvd.exe : fatal error LNK1120: 1 unresolved externals

William Vetterling
07-17-2003, 11:33 PM
The Numerical Recipes utility routine matrix() is defined in the file nrutil.c. Although the header file nrutil.h (which you have included in your example) provides prototypes for the NR utilities, it does not provide their definitions. Accordingly, you must compile nrutil.c link it with your program in order that references to these utilities be resolved. You will find the source code for nrutil.c in the directory of utility files along with nrutil.h.

As for xsvdcmp.c, you will find very complete instructions for compiling, linking and running this example routine in the document "Notes on Using Numerical Recipes in C with Various Windows Compilers". There is a link to this document at the bottom of the opening page of the NR in C distribution.

dddavid
07-24-2003, 01:57 AM
i cannot find the link. Could you give it?3X

William Vetterling
07-27-2003, 08:15 PM
I'm afraid it would not help for me to provide this link. It is not a link to an internet document, but rather an internal link within the HTML Numerical Recipes document itself. If you have the Numerical Recipes HTML-format distribution, just click on it and look at the bottom of the opening page for "Notes on Using Numerical Recipes in C with Various Windows Compilers". If you are using a version of the distribution other than the current HTML format, the road to success is to look at the Numerical Recipes web page at www.nr.com, and select "upgrades" to find out how to upgrade to the current version.

dddavid
08-03-2003, 09:27 PM
Could you send a copy? Thanks
donkeydavid@hotmail.com