gcc in linux

F

Fan Zhang

Hi again,

I am new to compiling C programs in Linux/Unix. I wanted to compile a
program by using gcc, but it turned out that gcc does not know where to
locate the library being called.

The program is as follows,

#include <math.h>
int main()
{
double ss;
double ff;
ss=1.0;
ff=sin(ss);
printf("%6.4f\n",ff);
return 0;
}

The error message is,

/tmp/ccIV3yAb.o: In function `main':
/tmp/ccIV3yAb.o(.text+0x1e): undefined reference to `sin'

The command I used to compile is
gcc test.c

Could anyone please let me know where I did wrong? Thanks!

Fan
 
?

=?ISO-8859-1?Q?=22Nils_O=2E_Sel=E5sdal=22?=

Fan said:
The error message is,

/tmp/ccIV3yAb.o: In function `main':
/tmp/ccIV3yAb.o(.text+0x1e): undefined reference to `sin'

The command I used to compile is
gcc test.c

Could anyone please let me know where I did wrong? Thanks!
You need to link with the math library which is called libm
so,
gcc test.c -lm
comp.os.linux.development.apps or comp.unix.programmer
is probably more appropriate for this Q though.
 
E

E. Robert Tisdale

Fan said:
I am new to compiling C programs in Linux/Unix.
I wanted to compile a program by using gcc
but it turned out that gcc does not know
where to locate the library being called.

The program is as follows,

#include <math.h>
int main()
{
double ss;
double ff;
ss=1.0;
ff=sin(ss);
printf("%6.4f\n",ff);
return 0;
}

The error message is,

/tmp/ccIV3yAb.o: In function `main':
/tmp/ccIV3yAb.o(.text+0x1e): undefined reference to `sin'

The command I used to compile is
gcc test.c

Could anyone please let me know where I did wrong? Thanks!

gcc test.c -lm
 
J

Jack Klein

Hi again,

I am new to compiling C programs in Linux/Unix. I wanted to compile a
program by using gcc, but it turned out that gcc does not know where to
locate the library being called.

Linux is not UNIX, UNIX is not Linux.
The program is as follows,

#include <math.h>
int main()
{
double ss;
double ff;
ss=1.0;
ff=sin(ss);
printf("%6.4f\n",ff);
return 0;
}

The error message is,

/tmp/ccIV3yAb.o: In function `main':
/tmp/ccIV3yAb.o(.text+0x1e): undefined reference to `sin'

The command I used to compile is
gcc test.c

Could anyone please let me know where I did wrong? Thanks!

Fan

Despite the fact that Linux is not UNIX, gcc on Linux continues the
old UNIX tradition of pretending that part of the standard C library
is not part of the standard C library.

UNIX elitists do not like to make things easy for the uninitiated,
unwashed masses, even when the reason for a particular piece of
stupidity has been obsolete for 20 years.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top