Link Errors
nevermind
11-15-2003, 11:04 PM
in trying to compile and link my project, i get the following link errors:
libration_project error LNK2001: unresolved external symbol "void __cdecl free_vector(double *,long,long)" (?free_vector@@YAXPANJJ@Z)
libration_project error LNK2019: unresolved external symbol "double * * __cdecl matrix(long,long,long,long)" (?matrix@@YAPAPANJJJJ@Z) referenced in function "void __cdecl broydn(double * const,int,int *,void (__cdecl*)(int,double * const,double * const))" (?broydn@@YAXQANHPAHP6AXH00@Z@Z)
libration_project error LNK2019: unresolved external symbol "double * __cdecl vector(long,long)" (?vector@@YAPANJJ@Z) referenced in function _main
libration_project error LNK2019: unresolved external symbol "void __cdecl free_matrix(double * *,long,long,long,long)" (?free_matrix@@YAXPAPANJJJJ@Z) referenced in function "void __cdecl broydn(double * const,int,int *,void (__cdecl*)(int,double * const,double * const))" (?broydn@@YAXQANHPAHP6AXH00@Z@Z)
libration_project error LNK2019: unresolved external symbol "void __cdecl free_vector(double *,long,long)" (?free_vector@@YAXPANJJ@Z) referenced in function _main
I have included the nrutil.c file into my project using Microsoft Visual Studio .NET 2003, and I've run out of ideas on how to resolve this link error. I'm afraid that I cannot include a copy of the code here, as it's much too long.
Any help is greatly appreciated.
Kyle DeMars
Sherlock
11-22-2003, 04:43 PM
Kyle,
The error messages suggest that there is some inconsistency in data types. Apparently you are using double precision instead of "float" for your vectors and arrays. In this case, the vectors will need to be created with "dvector()" instead of "vector()", and free'd with "free_dvector()" instead of "free_vector()". There are similar double precision versions of "matrix()" and "free_matrix()". You will see that most of the error messages involve calls to the single-precision versions being called with double-precision arguments, which is inconsistent with their prototype.
Also, be sure to use:
#include "nrutil.h"
in any routine that makes calls to the utility functions in "nrutil.c".
Giant
07-11-2005, 11:20 AM
I am having a similar problem and the above solution doesnt help me at all, is there another way to solve this problem ?
Fatima
10-10-2005, 07:59 PM
I have the same problem.
does anybody have solution for this?
Kevin Dolan
10-24-2005, 06:51 AM
You're compiling it with a C++ compiler, right?
Does the header file with the prototypes have something like
#ifdef __cplusplus
extern "C" {
#endif
at the beginning of it? If so, when you compile nrutil.c as a C++ file, you will get linking errors.
Likewise, if your header file does not have the above, and you compile the nr C files with a C compiler, you will get linking errors.
Kevin Dolan
mystical dervis
08-12-2008, 09:26 PM
I have the same problem
can some one help?
davekw7x
08-13-2008, 10:14 AM
I have the same problem...
Since the first post is the only one that actually articulates a problem and that was something like five years ago, let's recap:
First of all, are you getting an error like the following?
error LNK2019: unresolved external symbol "void __cdecl free_vector(double *,long,long)" (?free_vector@@YAXPANJJ@Z) referenced in function _main
Or is it like the following?
error LNK2019: unresolved external symbol "void __cdecl free_vector(float *,long,long)" (?free_vector@@YAXPAMJJ@Z) referenced in function _main
I don't see how anyone could get the first one unless some function declarations in nrutil.h had been modified from the original Numerical Recipes code. (Otherwise I think that there would have been compiler errors that would have stopped things before it got to the linking stage.)
For people who would like to help, it's important to know where your nrutil.c and nrutil.h came from. Are they from a Numerical Recipes CD or other "official" source? Or did you type them in from the book? Or did someone else give them to you? Or what?
One way that you might get the "Link2019" error message is if you included the header file "nrutil.h" but didn't actually compile the function implementation file "nrutil.c" and link its object file with your main program file.
Another way that the "Link2019" error message can appear is if your main program is in a file named "something.cpp" and the function definitions are in a file that has a ".c" extension (like "nrutil.c") and you compile them separately with a Microsoft compiler, using default compiler options.
The object files can't be linked unless they are all compiled as C files or they are all compiled as C++ files. (Symbol table entries for functions compiled by a C++ compiler have different names for the functions. It's a C++ thing.)
Since nrutil.c is a C file (not C++), I think that the most straightforward approach is to write C programs (not C++) and have your project file names "something.c" (not "something.cpp").
If you are using the Visual C++ Integrated Development Environment to compile your projects, then create a C project (not C++). Then your main program file will be "main.c" not "main.cpp" (or whatever other "something.c" name that you want to give it).
If you are compiling with the command-line compiler, then just make sure all of your project files are names "something.c", not "something.cpp"
If it really has to be a C++ main program file, then I can show a couple of ways to get it to play nice with nrutil.c, but you have to give us more information.
1. What version of Visual C++ are you using? The original Poster indicated the 2003 version. There are others. (The older Version 6; the newer 2005, 2008, ...) Sometimes it makes a difference to people who are trying to help.
2. Can you create and post a small program that shows how you declare and use Numerical Recipes vectors? Just call the vector() and free_vector() functions, but show us the complete main() function program (the small test program).
3. Tell us exactly how you compile and link the program files. Integrated Development project? Command line? What? I think that it's easiest to get help with fewest iterations if you compile with the command line compiler, cl.exe, since we can tell exactly what is getting compiled and how. It's usually really, really difficult to debug someone's IDE project by remote control because we can't know what your project settings are.
4. Show us the exact error messages. If there are any compiler warnings or any other compiler or linker messages, show them exactly as the compiler gives them to you. Don't paraphrase.
Regards,
Dave