math.h problem

Fabio Mazzone mazzone@ge.infm.it
Mon Jan 13 16:09:00 GMT 2003


try with a -l or -lm option to gcc (i'm sorry, i don't remeber it and i
can't run it now...).

----- Original Message -----
From: "Anant Aneja" <anantaneja@rediffmail.com>
To: <gcc-help@gcc.gnu.org>
Sent: Monday, January 13, 2003 4:24 PM
Subject: math.h problem


> Hi all,
> I recently instatalled gcc version 2.96 on my Pentium 2 350 Mhz
> running PCQLinux (just
> Red Hat 7.1 renamed)
>
> I could get string.h,ctype.h to work but am havin problems with
> math.h
>
> I by chance stumbled to a query posted in Aug 2001 reagarding a
> similar problem with math.h
> I read ur reply and so am supplying u with all the details. Tell
> me what is wrong.
>
> file mtest.c :
> ------mtest.c--------------
> #include <math.h>
>
> int main(void)
> {
> double n;
>
>    n = sqrt(2);
>    return (int)n - 1;
> }
> ----------------------------
>
> command run :
>   gcc -v mtest.c -o mtest
>
> o/p:
> ---------Starts----------
> Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.96/specs
> gcc version 2.96 20000731 (Red Hat Linux 7.1 2.96-81)
>   /usr/lib/gcc-lib/i386-redhat-linux/2.96/cpp0 -lang-c -v
> -D__GNUC__=2 -D__GNUC_M
> INOR__=96 -D__GNUC_PATCHLEVEL__=0 -D__ELF__ -Dunix -Dlinux
> -D__ELF__ -D__unix__
> -D__linux__ -D__unix -D__linux -Asystem(posix) -Acpu(i386)
> -Amachine(i386) -Di38
> 6 -D__i386 -D__i386__ -D__tune_i386__ mtest.c /tmp/ccBL7IJ3.i
> GNU CPP version 2.96 20000731 (Red Hat Linux 7.1 2.96-81) (cpplib)
> (i386 Linux/E
> LF)
> ignoring nonexistent directory "/usr/local/include"
> ignoring nonexistent directory "/usr/i386-redhat-linux/include"
> #include "..." search starts here:
> #include <...> search starts here:
>   /usr/lib/gcc-lib/i386-redhat-linux/2.96/include
>   /usr/include
> End of search list.
>   /usr/lib/gcc-lib/i386-redhat-linux/2.96/cc1 /tmp/ccBL7IJ3.i
> -quiet -dumpbase mt
> est.c -version -o /tmp/cc1gOa36.s
> GNU C version 2.96 20000731 (Red Hat Linux 7.1 2.96-81)
> (i386-redhat-linux) comp
> iled by GNU C version 2.96 20000731 (Red Hat Linux 7.1 2.96-81).
>   as -V -Qy -o /tmp/ccu4nMfe.o /tmp/cc1gOa36.s
> GNU assembler version 2.10.91 (i386-redhat-linux) using BFD
> version 2.10.91.0.2
>   /usr/lib/gcc-lib/i386-redhat-linux/2.96/collect2 -m elf_i386
> -dynamic-linker /l
> ib/ld-linux.so.2 -o mtest
> /usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../crt1.
> o /usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../crti.o
> /usr/lib/gcc-lib/i386-
> redhat-linux/2.96/crtbegin.o
> -L/usr/lib/gcc-lib/i386-redhat-linux/2.96 -L/usr/li
> b/gcc-lib/i386-redhat-linux/2.96/../../.. /tmp/ccu4nMfe.o -lgcc
> -lc -lgcc /usr/l
> ib/gcc-lib/i386-redhat-linux/2.96/crtend.o
> /usr/lib/gcc-lib/i386-redhat-linux/2.
> 96/../../../crtn.o
> /tmp/ccu4nMfe.o: In function `main':
> /tmp/ccu4nMfe.o(.text+0x11): undefined reference to `sqrt'
> collect2: ld returned 1 exit status
>
> ----------Ends------------
>
> command :
>   gcc -v mtest.c -o mtest.i -E
>
> o/p:
> ----------Starts------------
> Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.96/specs
> gcc version 2.96 20000731 (Red Hat Linux 7.1 2.96-81)
>   /usr/lib/gcc-lib/i386-redhat-linux/2.96/cpp0 -lang-c -v
> -D__GNUC__=2 -D__GNUC_M
> INOR__=96 -D__GNUC_PATCHLEVEL__=0 -D__ELF__ -Dunix -Dlinux
> -D__ELF__ -D__unix__
> -D__linux__ -D__unix -D__linux -Asystem(posix) -Acpu(i386)
> -Amachine(i386) -Di38
> 6 -D__i386 -D__i386__ -D__tune_i386__ mtest.c /tmp/ccBL7IJ3.i
> GNU CPP version 2.96 20000731 (Red Hat Linux 7.1 2.96-81) (cpplib)
> (i386 Linux/E
> LF)
> ignoring nonexistent directory "/usr/local/include"
> ignoring nonexistent directory "/usr/i386-redhat-linux/include"
> #include "..." search starts here:
> #include <...> search starts here:
>   /usr/lib/gcc-lib/i386-redhat-linux/2.96/include
>   /usr/include
> End of search list.
>   /usr/lib/gcc-lib/i386-redhat-linux/2.96/cc1 /tmp/ccBL7IJ3.i
> -quiet -dumpbase mt
> est.c -version -o /tmp/cc1gOa36.s
> GNU C version 2.96 20000731 (Red Hat Linux 7.1 2.96-81)
> (i386-redhat-linux) comp
> iled by GNU C version 2.96 20000731 (Red Hat Linux 7.1 2.96-81).
>   as -V -Qy -o /tmp/ccu4nMfe.o /tmp/cc1gOa36.s
> GNU assembler version 2.10.91 (i386-redhat-linux) using BFD
> version 2.10.91.0.2
>   /usr/lib/gcc-lib/i386-redhat-linux/2.96/collect2 -m elf_i386
> -dynamic-linker /l
> ib/ld-linux.so.2 -o mtest
> /usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../crt1.
> o /usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../crti.o
> /usr/lib/gcc-lib/i386-
> redhat-linux/2.96/crtbegin.o
> -L/usr/lib/gcc-lib/i386-redhat-linux/2.96 -L/usr/li
> b/gcc-lib/i386-redhat-linux/2.96/../../.. /tmp/ccu4nMfe.o -lgcc
> -lc -lgcc /usr/l
> ib/gcc-lib/i386-redhat-linux/2.96/crtend.o
> /usr/lib/gcc-lib/i386-redhat-linux/2.
> 96/../../../crtn.o
> /tmp/ccu4nMfe.o: In function `main':
> /tmp/ccu4nMfe.o(.text+0x11): undefined reference to `sqrt'
> collect2: ld returned 1 exit status
> [anant@aneja anant]$ cat > op.txt
> [anant@aneja anant]$ gcc -v mtest.c -o mtest
> Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.96/specs
> gcc version 2.96 20000731 (Red Hat Linux 7.1 2.96-81)
>   /usr/lib/gcc-lib/i386-redhat-linux/2.96/cpp0 -lang-c -v
> -D__GNUC__=2 -D__GNUC_M
> INOR__=96 -D__GNUC_PATCHLEVEL__=0 -D__ELF__ -Dunix -Dlinux
> -D__ELF__ -D__unix__
> -D__linux__ -D__unix -D__linux -Asystem(posix) -Acpu(i386)
> -Amachine(i386) -Di38
> 6 -D__i386 -D__i386__ -D__tune_i386__ mtest.c /tmp/ccBL7IJ3.i
> GNU CPP version 2.96 20000731 (Red Hat Linux 7.1 2.96-81) (cpplib)
> (i386 Linux/E
> LF)
> ignoring nonexistent directory "/usr/local/include"
> ignoring nonexistent directory "/usr/i386-redhat-linux/include"
> #include "..." search starts here:
> #include <...> search starts here:
>   /usr/lib/gcc-lib/i386-redhat-linux/2.96/include
>   /usr/include
> End of search list.
>   /usr/lib/gcc-lib/i386-redhat-linux/2.96/cc1 /tmp/ccBL7IJ3.i
> -quiet -dumpbase mt
> est.c -version -o /tmp/cc1gOa36.s
> GNU C version 2.96 20000731 (Red Hat Linux 7.1 2.96-81)
> (i386-redhat-linux) comp
> iled by GNU C version 2.96 20000731 (Red Hat Linux 7.1 2.96-81).
>   as -V -Qy -o /tmp/ccu4nMfe.o /tmp/cc1gOa36.s
> GNU assembler version 2.10.91 (i386-redhat-linux) using BFD
> version 2.10.91.0.2
>   /usr/lib/gcc-lib/i386-redhat-linux/2.96/collect2 -m elf_i386
> -dynamic-linker /l
> [anant@aneja anant]$ gcc -v mtest.c -o mtest.i -E
> Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.96/specs
> gcc version 2.96 20000731 (Red Hat Linux 7.1 2.96-81)
>   /usr/lib/gcc-lib/i386-redhat-linux/2.96/cpp0 -lang-c -v
> -D__GNUC__=2 -D__GNUC_M
> INOR__=96 -D__GNUC_PATCHLEVEL__=0 -D__ELF__ -Dunix -Dlinux
> -D__ELF__ -D__unix__
> -D__linux__ -D__unix -D__linux -Asystem(posix) -Acpu(i386)
> -Amachine(i386) -Di38
> 6 -D__i386 -D__i386__ -D__tune_i386__ mtest.c -o mtest.i
> GNU CPP version 2.96 20000731 (Red Hat Linux 7.1 2.96-81) (cpplib)
> (i386 Linux/E
> LF)
> ignoring nonexistent directory "/usr/local/include"
> ignoring nonexistent directory "/usr/i386-redhat-linux/include"
> #include "..." search starts here:
> #include <...> search starts here:
>   /usr/lib/gcc-lib/i386-redhat-linux/2.96/include
>   /usr/include
> End of search list.
>
> -------------Ends-----------
>
> A similar problem occurs on using iostream.h :
>
> -------iotest.cpp--------
> #include <iostream.h>
>
> void main()
> {
> char a;
> cin>>a;
> }
> -----------Ends------------
>
> on givin :
> gcc iotest.cpp i get :
> ------Starts-----------
> /tmp/ccBRsi6r.o: In function `main':
> /tmp/ccBRsi6r.o(.text+0xe): undefined reference to `cin'
> /tmp/ccBRsi6r.o(.text+0x13): undefined reference to
> `istream::operator>>(char &)'
> collect2: ld returned 1 exit status
>
> ----------Ends---------
>
> Basically as u must have noticed the problem is a "undefined
> refreance to <func. name>"
>
> Hoping u'll help me,
> Anant Aneja
>
> anantaneja@rediffmail.com
> anantaneja@yahoo.com
>
>




More information about the Gcc-help mailing list