-2

Are ran1,ran2, ran3 functions are included in the library ? Does these needs some header file or package ? How to mention in the program and how to call .

I just know the basic programmings .I am trying to learn random variable generators .I have looked in the book numerical recipe there are three functions ran1,ran2 and ran3.I want to know how this function called or used in the program ? How to mention this functions in my program?

pjs
  • 18,696
  • 4
  • 27
  • 56
Novice
  • 3
  • 4
  • 1
    "Are ran1,ran2, ran3 functions are included in the library?" Which library are you referring to when you write "the library"? From a little Internet searching, the functions `ran1`, `ran2`, and `ran3` are part of the book itself. Here's a research paper that studies the first two. https://www.sciencedirect.com/science/article/abs/pii/S0167947398800029 – Raymond Chen Jan 27 '23 at 21:50
  • They're probably not included in the regular C library on your machine. They might be in some other library. There should be a header that gives the prototypes for the functions; you'd include that header in your source code, following the guidelines in the documentation and examples (likely to be `#include "someheader.h"` or `#include "somewhere/someheader.h"`, though they may recommend angle brackets `<>` instead of quotes `""` around the header name. You need to specify the appropriate location on the command line with `-I/location/library/include` (or similar). – Jonathan Leffler Jan 27 '23 at 21:58
  • 1
    You may need to specify a library and its location on the command line too: `-L/location/library/lib` and `-lsomename` (this should go after your object files on the command line). You may have to install the software. It may already be there. Since the names are non-standard, it's hard to be sure. – Jonathan Leffler Jan 27 '23 at 21:59

1 Answers1

0

In order to use a function (ran1(), ran2() or ran3()) from a library X you usually have to include the header in your_file.c:

#include <X.h>

Tell the compiler which directory to find said header if it's in a non-standard location. Say, the header is path/include/X.h, then you would compile the file with:

gcc -Ipath/include -c your_file.c

And you link the library by using the -L to tell where the dynamic library is located, say, path/lib/libX.so:

gcc -Lpath/lib -lX your_file.o -o your_file

If your library ships with a .pc file then you use pkg-config --cflags libX for the compilation, and pkg-config --libs libX for linking. Note there is some variability in the naming of the pc file so look at what your library uses if any.

Allan Wind
  • 23,068
  • 5
  • 28
  • 38