Compiling linux applications

Malcolm Kay malcolm.kay at internode.on.net
Mon Dec 26 05:49:58 PST 2005


On Mon, 26 Dec 2005 01:46 pm, TV JOE wrote:
> Hi,
>
>  I've a C program written for Suse linux. I'm having minor
> problems compiling. First is that the cexp (complex exponent)
> is not available in /usr/include/math.h. Is it possible to add
> on a library that includes this function? I compile as 'gcc
> -lm program.c'.
>

Mathematically the complex exponent is
  exp(real_part)*(cos(imag_part)+i*sin(imag_part)
and by the standard has the prototype:

#include <complex.h>
  double complex cexp(double complex z);

So you can easily define it for yourself:

#include <complex.h>
#include <math.h>
double complex cexp(double complex z){
   return exp(creal(z))*(cos(cimag(z)) + sin(cimag(z))*I);
}

Or even perhaps as a macro:
#include <complex.h>
#include <math.h>
#define cexp(z) (exp(creal(z))*(cos(cimag(z)) + sin(cimag(z))*I))

>  Additionally there is a timer program that creates this
> compile error
>
> GC.c: In function `gettime':
> GC.c:252: error: storage size of 'ltim' isn't known
>
>  Here is gettime
>
> /*************************************************************
>*******/ // Functions start here.
> /*************************************************************
>*******/
>
> // Function to read system time.  Only used for testing
> execution speed. long int gettime(void)
> {
>     struct timeval    ltim;

This is easy; you don't have the definition of the struct timeval
in scope. It is defined in <unistd.h>
So add
#include <unistd.h>
near the beginning of the source file.

Malcolm

>
>         gettimeofday(&ltim, NULL);
>         return (((long int)ltim.tv_sec)*((long
> int)(1000000))+((long int)ltim.tv_usec)); }
>
>
>  I'm compiling on a 5.3 box. Thanks for any help,
>


More information about the freebsd-questions mailing list