Problems setting up NR C++


andrew
08-28-2004, 06:17 AM
Hi,

I have recently purchased the NRC++ book and downloaded the code for Liinux (running Suse 9.1 with gcc version 3.3.3-41)
I tring to create the object file using the make command as detailed in the documentation. I changed the CC to a cc and tried gcc but I get the following errors:
------------------------
cc -I/usr/local/src/recipes_cpp/utils -I. -o xairy.out xairy.o airy.o bessik.o bessjy.o beschb.o chebev.o -lm
xairy.o(.text+0x1c): In function `main':
: undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string[in-charge]()'
xairy.o(.text+0x35): In function `main':
: undefined reference to `std::basic_ifstream<char, std::char_traits<char> >::basic_ifstream[in-charge](char const*,
------------ and a lot more!

I also run into errors tring to include the code directly into any programs a write. I include the nr.h header into my program and this works fine, but I can't seem to access the routines by calling them directly. For example the following code from the example on page 2 of the book fails:

for(i=0 ;i<NTOT ;i++ ){
flmoon(i,nph,jd,frac);
}

with the message:

/hi.cpp:36: error: `flmoon' undeclared (first use this function)

If any one can help I would truly appreciate it.
Andrew:confused:

Saul Teukolsky
08-29-2004, 04:59 PM
Hi Andrew,

NR certainly works under linux with gcc. Sounds like your setup has trouble finding things that are in the standard library. Write a little test program that declares a string and uses cout to output it. Whatever you need to get it to compile is what you need to do to get the makefile to work.

For your second problem, the NR routines are all in the namespace NR. To use them you need a declaration, and the simplest way to do this is to include
nr.h. You also need to say e.g. NR::flmoon or using NR (to use all the routines).

Hope this helps.

Saul Teukolsky

andrew
08-30-2004, 03:30 AM
Hi Saul

Thanks. Problem partially solved. All standard basic routines compile fine under gcc. I can use all iostream routines like cout, call in header files, link the project. I am using KDevelop to write my routines and add the numerical recipes code as existing files (I had not done this correctly previously :mad: and this is the reason for some of the errors) So now I can run all routines (well the ones that I've tried).

I still have the following problems though:

I can't run the makefile that come with the recipes to create the object code without serious errors. Did this work without problems for you? Did you have to modify the makefile beyond changing the target? If I can' run the makefile this means the object code for the routines is not generated and I have to include all the recipes I need into any code as existing files and then compile. This is not such a major hassle as I will compile the routines to object individually and add them to my gcc path (/usr/local/include or someting like that) at a later stage.

I'll keep you posted on progress.
Thanks
Andrew

davidwrx
09-28-2004, 08:17 PM
I just want to say that the makefile doesn't run completely either on my system. (Fedora Core 1) I'm kind of new to this makefile stuff too, so I don't really know what to do to modify it so it runs correctly.