🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.help
Article #42001

Re: gcc compiler/linker question

#42001
From: Carlos Linares
Date: Fri, 26 Jan 1996 00:00
48 lines
2301 bytes
Hi!

lanx@siu.EDU wrote:
>I installed gcc together with Linux from the Linux Slackware package. The
>bin, include and lib directories are directly under /usr, which is different
>from what you described for a separate installation in which they should be
>under /usr/local. Anyway, gcc generally works except it can not find the
>intrinsic functions (like sin, sqrt, etc.) that need <math.h>. My test
>program is like this:
>
>#include <stdio.h>
>#include <math.h>
>main()
>{
> double x;
> x=sin(3.14159/6.0);
> printf("x=%f\n",x);
>}
>
>when I used gcc to compile and link the program, it gave me an error message:
>/tmp/xxxxxxxx:   undefined reference to 'sin'
>I checked /usr/include directory, both stdio.h and math.h are there! Do you
>know what the problem is? Please help me.
>Jian
>

Have you tried to use the -lm option? If not, do it, ... If that was your
problem look in /usr/faq/faq where you'll find many faqs about gcc (it is 
necessary to install the F series, of course)

In brief, it is necessary to use -l option when you want to use any library
in /usr/include, like, for instance, libm.a, the mathematical library. When 
you want to use such a library you must include -lxxx, where xxx is the name of
the library, without the initial letters 'lib' and without the last ones '.a',
so, for 'libm.a' you'll need '-lm'. Notice that -l option must be put the last
one, so, for compiling your prog, you ought to do something like:

% gcc proof.c -o proof -lm

if your prog was called proof.c

I hope this helps

Carlos Linares Lopez
Artificial Intelligence Laboratory
Computer Science Faculty
Polithecnic University of Madrid
Spain
Technical Details
Message-ID: <4eallr$888@panoramix.fi.upm.es>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <9601170739.AA21890@saluki-mail.fiber2.siu.edu>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11318c,e36285420ed23a4f
X-Google-Attributes: gid11318c,public
From: Carlos Linares <clinares>
Subject: Re: gcc compiler/linker question
Date: 1996/01/26
Message-ID: <4eallr$888@panoramix.fi.upm.es>
X-Deja-AN: 136681837
references: <9601170739.AA21890@saluki-mail.fiber2.siu.edu>
content-type: text/plain; charset=us-ascii
organization: Facultad de Informatica de Madrid - U.P.M.
x-url: news:9601170739.AA21890@saluki-mail.fiber2.siu.edu
mime-version: 1.0
newsgroups: gnu.gcc.help
x-mailer: Mozilla 1.12 (X11; I; SunOS 4.1.3_U1 sun4m)