This is the mail archive of the gsl-discuss@sources.redhat.com mailing list for the GSL project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: sincos ( a little off-topic)


Hi Daniel,

Daniel Rohe <d.rohe@fkf.mpg.de> writes:

> I'm trying to use the sincos function which is supposed to be provided
> by libc. however all I get is the following compiler error:
> 
> test_math.C: In function `int main()':
> test_math.C:26: implicit declaration of function `int sincos(...)'

>From the libc Manual:

==================================

Feature Test Macros
-------------------

   The exact set of features available when you compile a source file
is controlled by which "feature test macros" you define.

[...]

   You should define these macros by using `#define' preprocessor
directives at the top of your source code files.  These directives
_must_ come before any `#include' of a system header file.  It is best
to make them the very first thing in the file, preceded only by
comments.  You could also use the `-D' option to GCC, but it's better
if you make the source files indicate their own meaning in a
self-contained way.

[...]

 - Macro: _GNU_SOURCE
     If you define this macro, everything is included: ISO C89,
     ISO C99, POSIX.1, POSIX.2, BSD, SVID, X/Open, LFS, and GNU
     extensions.  In the cases where POSIX.1 conflicts with BSD, the
     POSIX definitions take precedence.

=============================================

So the following works:

/home/reimar/test $ cat sincos.c 
#define _GNU_SOURCE
#include <math.h>
#include <stdio.h>

int main (void)
{
  double x = M_PI, s, c;
  sincos (x, &s, &c);
  printf ("%f %f %f\n", x, s, c);
  return 0;
}

/home/reimar/test $ gcc -W -Wall -pedantic sincos.c -lm
/home/reimar/test $ ./a.out 
3.141593 0.000000 -1.000000
/home/reimar/test $ 

Hope that helps,

Reimar



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]