Numerical Recipes Forum  

Go Back   Numerical Recipes Forum > Obsolete Editions Forum > General Problems in Using NR

Reply
 
Thread Tools Display Modes
  #1  
Old 01-07-2009, 02:21 AM
guy.tikochinsky guy.tikochinsky is offline
Registered User
 
Join Date: Jul 2008
Posts: 3
Question Compile *.c files

In general how do I compile my *.c files that uses the nr files?
Reply With Quote
  #2  
Old 01-07-2009, 09:49 AM
davekw7x davekw7x is offline
Registered User
 
Join Date: Jan 2008
Posts: 452
Quote:
Originally Posted by guy.tikochinsky View Post
In general how do I ...
There is no "general" set of instructions for compiling any C program, so the answer to, "How do I ... ?" is: "It depends."

How about giving us some details of your setup?

What compiler?
What Operating System?
What kind of directory structure? (Where are your NR distribution files? Where are your project source files?)


How do you compile your other (non-NR) *.c programs?

Command line?
Makefile?
Integrated Development Environment?
What?

Regards,

Dave

Last edited by davekw7x; 01-07-2009 at 11:31 AM.
Reply With Quote
  #3  
Old 01-08-2009, 04:01 AM
guy.tikochinsky guy.tikochinsky is offline
Registered User
 
Join Date: Jul 2008
Posts: 3
Compile *.c files

Hi,

Thanks for your respone.

I am using openSUSE 10.3 (i586) - Kenet 2.6

The compiler is gcc version 4.2.1

The directory structure is /usr/local/src/NR_C301/legacy/nr2/C_211

I am trying to compile one of the example.

I compile all the NR routine
.../recipes#gcc -v -I../other -I/usr/include *.c

=> rlftfrag.c:30: error: redefinition of 'main'
rlftfrag.c:9: error: previous definition of 'main' was here
rlftfrag.c:50: error: redefinition of 'main'
rlftfrag.c:9: error: previous definition of 'main' was here

.../recipes#ar cr libnr.a *.c

=> then I got file "libnr.a"

.../examples#gcc -g xjulday.c -I../other -I/usr/include -o xjulday -L ../recipes -lm

=>In file includes from xjulday.c:7:
../other/nr.h:423: error: conflivting type for 'select'
/usr/include/sys/select.h:112: error: previous declaration of 'select' was here

Thanks in Advance
Reply With Quote
  #4  
Old 01-08-2009, 09:09 AM
davekw7x davekw7x is offline
Registered User
 
Join Date: Jan 2008
Posts: 452
Quote:
Originally Posted by guy.tikochinsky View Post
=>In file includes from xjulday.c:7:
../other/nr.h:423: error: conflivting type for 'select'
/usr/include/sys/select.h:112: error: previous declaration of 'select' was here
For a start, I would suggest that you make sure that you don't change the original nr.h. Keep it just in case...

So, I suggest that you move the original nr.h to a "safe" directory. Make a copy in the recipes directory. Then comment out line 423 of nr.h in the recipes directory.
Code:
/*float select(unsigned long k, unsigned long n, float arr[]); */
Then try compiling the test program again.

I assume that you meant to tell it to use libnr.a, so: Maybe the compile command would be something like
Code:
gcc -g xjulday.c -I../other -o xjulday -L../recipes -lnr -lm
When you execute the test program, if it tells you that it can't find the data file, then you can copy dates1.dat from the ../data directory to the examples directory.

If this doesn't work, and you can't figure out why, then post again and tell us what happened. Don't try any of the following until you get a successful compilation and execution of xjulday.

If this does work, you will have to do something about the NR select() function in case you ever need it.

Here is what I did, way back when...

I made a copy of the select.c file in the recipes directory and called it nrselect.c, then I moved the original select.c to the "safe" directory.

I changed all references to the select() function in the files in NR recipes and examples and other directories to nrselect(). (I did this after moving the affected files to the "safe" directory and making copies back in their original directories.)

If you haven't done this already, don't forget to go back into your new nr.h and change line 423.

Code:
float nrselect(unsigned long k, unsigned long n, float arr[]);
At this point, I would delete libnr.a and recompile the entire library, since several recipes files have been changed.

Then try compiling various files in the examples directory. Let us know how it works out.


Regards,

Dave

Footnotes:
1. The above worked on my Centos 5 workstation (GNU gcc Version 4.1.2).

2. I also moved all files in the recipes directory with a main() function to another directory before compiling the library so that there wouldn't be any files in the library with a main() function. A minor point, maybe, but I like things to be as clean as possible (within reason).

Last edited by davekw7x; 01-08-2009 at 04:41 PM.
Reply With Quote
  #5  
Old 01-11-2009, 12:39 AM
guy.tikochinsky guy.tikochinsky is offline
Registered User
 
Join Date: Jul 2008
Posts: 3
Hi Dave,

thanks a lot. It's working.

Guy
Reply With Quote
  #6  
Old 04-22-2009, 11:30 AM
squidx squidx is offline
Registered User
 
Join Date: Apr 2009
Posts: 2
I'm also having a problem compiling my *.c files

I'm new at c, which is why I'm trying to work with the NR in the first place.

When I downloaded the files, they did not come with any clear instructions or any Makefiles that I could see.

I'm using Linux (ubuntu) and CLI gcc. My initial goal is to get lu decomposition working, with the old c code version. And I'm kind of in a panic -- I was expecting this part of my work to be a piece of cake, yet I'm wasting all kinds of time on it.

I've tried all kinds of things, some of which gave me *.a library files, with no good results. What I'm hoping for, (against hope?) is a way to just collect all the necessary files in a directory (copied, not original) and *either* some commands to make the libraries I need, *or* the proper gcc "incantations" to just attach the NR .c and .h files and compile my code.

If I can even get the calendar demo going, I'll be better off.

It seems like others here have done it - please help!
Thanks,
Alex
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is On

Forum Jump


All times are GMT -5. The time now is 08:25 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.