[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to use trigonometric functions in Swarm?
From: |
Gary Polhill |
Subject: |
Re: How to use trigonometric functions in Swarm? |
Date: |
Mon, 19 Jun 2000 12:22:27 +0100 |
Perrone Alessandro wrote:
>
> Hi
> I have to use in my simulation some trigonometric functions.
> I imported the right header, but when I call the sin(x) function, an
> error occur!!
> I am using Linux on my Imac, with Swarm 2.1.1
> Here it is the result with a simple program:
>
> ------
> address@hidden apps]# gcc alex.c -o alex
> /tmp/ccHDfVDm.o: In function `main':
> /tmp/ccHDfVDm.o(.text+0x20): undefined reference to `sin'
> /tmp/ccHDfVDm.o(.text+0x20): relocation truncated to fit: R_PPC_REL24 sin
> collect2: ld returned 1 exit status
> address@hidden apps]# more alex.c
> #include <stdio.h>
> #include <math.h>
>
> int main () {
> float a;
> a=(float) sin((double) 1.0);
> printf("%f\n",a);
> return 0;
> }
> address@hidden apps]# gcc -I/usr/include alex.c -o alex
> /tmp/cck3PTSF.o: In function `main':
> /tmp/cck3PTSF.o(.text+0x20): undefined reference to `sin'
> /tmp/cck3PTSF.o(.text+0x20): relocation truncated to fit: R_PPC_REL24 sin
> collect2: ld returned 1 exit status
> address@hidden apps]#
This is a linker error -- you need a -lm to tell it to link in the
maths library (i.e. in the compile command above, do
gcc -I/usr/include alex.c -o alex -lm
If your libm.a is not in a standard location you will need a
-L/path/to/math/library in there as well (where /path/to/math/library is
replaced by the appropriate directory path).
You should not have this problem when compiling with swarm -- I'm fairly
sure it already links in the maths library -- this may be different in
Swarm 2.x -- I'm still on 1.4.1 :-( If not, you could add an APPLIBS=-lm
line in your makefile (or if you already have an APPLIBS line, add -lm to the
end of that -- again, this could be different in versions of Swarm higher
than 1.4.1....
Gary
--
Macaulay Land Use Research Institute, Craigiebuckler, Aberdeen. AB15 8QH
Tel: +44 (0) 1224 318611 Email: address@hidden
==================================
Swarm-Support is for discussion of the technical details of the day
to day usage of Swarm. For list administration needs (esp.
[un]subscribing), please send a message to <address@hidden>
with "help" in the body of the message.