nag_random_normal() fails

Hello, everyone. I new to this forum as a fresh C++ user. Here is my problem. I use NAG random number generator to generate numbers with Microsoft Visual C++ 2008 on my Windows notebook. The NAG include files are already attached in the option menu. But the compiler still complains about the nag function. Here is my code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <time.h>
#include <math.h>

#include <nag.h>
#include <nag_stdlib.h>
#include <nagg01.h>
#include <nagg05.h>

using namespace std;

int main()
{
//	nag_random_init_nonrepeatable(); 
	double x ;
	x = nag_random_normal(0,1);

	cout<<"The random number is "<<x<<"\n";
	cin.get();
}


I just generate a random number and send it to the cout. I got error message:
error LNK2019: link to unresolved external symbol "__imp__g05ddc@16" in funktion "_main". Even when I used the "nag_random_init_nonrepeatable();" line.
The funny thing is that the nag random number generator works in another project I have. Can someone help me with this? Thanks!
Have you linked in the appropriate libraries ??
Thanks for the quick reply. How do i do this?
What happens if you get rid of math.h - comment it out then compile? Or comment out nagg05.h
To Mythios:
Getting rid of math.h doesn't change anything. It seems indeed redundant. Header nagg05.h cannot miss. I tried this scenario , errors occured :
error C3861: "g05ccc": Identifier not found
error C3861: "g05ddc": Identifier not found
both referring to the nag_random commands.
This nag.h - i haven't heard of it before, whered you get this from?
Sorry just looked it up. Do you have any other examples of using it?
Last edited on
Hmm only other thing i can think of is - try the nag includes putting them in "" instead of <> ... and for your main - add a return 0;
Last edited on
The nag*.h files are headers of NAG routines provided by NAG C Library. Here more info:
http://www.nag.co.uk/numeric/CL/nagdoc_cl08/html/G05/g05_conts.html
The same nag_random_normal() works fine in another project. I guess the problem is maybe some inappropriate configuration specific to this project, as suggested by guestgulkan. But I did include the nag library. Otherwise it wouldn't ve worked in another project.
What do you mean when you say "you did include the nag library"?
Libraries are much more than header files.

There should be one or more files with the extension .lib and one or more dll files that came with the NAG library.
(The dll files are usually in the windows\system32 directory).

You need to link the NAG related .lib (library) file(s) with your project.
This is not being done and thay is why you are getting unresolved external symbol errors
Do you know how to tell Microsoft Visual studio to link in (additional) .lib files??

Last edited on
You could always list what your includes and libraries say
Just to prove a point: I just downloaded the NAG libraries (Windows XP).
It installed to the directory C:\Program Files\NAG\CL08\

I opened a new project in Visual Studio and pasted your code.
Ran it - NOT OK - (as I had not told it which LIB and the path to that LIB to link with).

I displayed the project properties, and on the linker->General page
I added C:\Program Files\NAG\CL08\clw3208dbl\lib to the Additional Library Directories field

On Linker->Input, I added C:\Program Files\NAG\CL08\clw3208dbl\lib to the Additional Dependencies field

Code now compiles and link and ran ok.
Note: Im not sure where your NAG is installed and the name of the .lib file maybe slightly different on yours depending on the version - but I think you get the idea.
Note also - you may find more that one .lib file - you can add them all, or try them one by one if you don't know which particular one to link with.

There should also be a help file(html) if you need further info in the doc directory
Last edited on
Well at the least now theres a solution - and you can pretty much see if you follow what you said it'll work. Nice work gg
to guestgulkan:
well, I do not know how to do this. More tips?
that`s it. I added a "nagc.lib" to the additional library and it worked! Thank you guys, especially guestgulkan!
Nice, Problem was fixed then :)
Topic archived. No new replies allowed.