Thread View: comp.os.linux.setup
6 messages
6 total messages
Started by Chano GĂłmez MartĂnez
Tue, 16 Apr 1996 21:52
problems with GCC
Author: Chano GĂłmez MartĂnez
Date: Tue, 16 Apr 1996 21:52
Date: Tue, 16 Apr 1996 21:52
74 lines
3941 bytes
3941 bytes
First of all, I want to apologize for my awful English. Now, the C stuff : I'm trying to port a C program from Borland C++ 3.1 to GCC under Linux. My problem is that I can't use any function from math.h !!! The file is correctly #include'd ( in fact, I get no compilation errors ) but the linker always tells me something like : /tmp/cca000971.o(.text+0x39): undefined reference to `exp' The funny thing is that GPC ( the GNU Pascal compiler ) allows me to use math.h functions lihe exp(), sin(), fabs(), etc, but when I convert my Pascal programs to C with p2c and try to compile them with GCC , I get the same error again. Here is the result from compiling the Pascal source with GPC -v ... ================================================ Reading specs from /usr/lib/gcc-lib/i486-linux/2.6.3/specsgcc version 2.6.3 /usr/lib/gcc-lib/i486-linux/2.6.3/gpc-cpp -lang-pascal -v -nocharescape -undef -D__GNUC__=2 -D__GPC__=2 -D__GNUC_MINOR__=6 -D__ELF__ -D__unix__ -D__i386__ -D__linux__ -D__unix -D__i386 -D__linux -Asystem(unix) -Asystem(posix) -Acpu(i386) -Amachine(i386) -D__i486__ mat.p /tmp/cca00103.iGNU CPP version 2.6.3 (i386 Linux/ELF)#include "..." search starts here:#include <...> search starts here: /usr/local/include /usr/i486-linux/include /usr/lib/gcc-lib/i486-linux/2.6.3/include /usr/includeEnd of search list. /usr/lib/gcc-lib/i486-linux/2.6.3/gpc1 /tmp/cca00103.i -quiet -dumpbase mat.pas -version -o /tmp/cca00103.sGNU PASCAL version 2.6.3 (i386 Linux/ELF) compiled by GNU C version 2.6.3. /usr/i486-linux/bin/as -V -Qy -o /tmp/cca001031.o /tmp/cca00103.sGNU assembler version cygnus/linux-2.5.2l.15 (i486-linux), using BFD version cygnus/linux-2.5.2l.11 /usr/i486-linux/bin/ld -m elf_i386 -dynamic-linker /lib/ld-linux.so.1 /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/crtbegin.o -L/usr/lib/gcc-lib/i486-linux/2.6.3 -L/usr/i486-linux/lib /tmp/cca001031.o -lgpc -lgcc -lm -lc -lgcc /usr/lib/crtend.o /usr/lib/crtn.o ===================== and now the result from GCC : ============================= Reading specs from /usr/lib/gcc-lib/i486-linux/2.7.0/specsgcc version 2.7.0 /usr/lib/gcc-lib/i486-linux/2.7.0/cpp -lang-c -v -undef -D__GNUC__=2 -D__GNUC_MINOR__=7 -D__ELF__ -Dunix -Di386 -Dlinux -D__ELF__ -D__unix__ -D__i386__ -D__linux__ -D__unix -D__i386 -D__linux -Asystem(unix) -Asystem(posix) -Acpu(i386) -Amachine(i386) -D__i486__ mat.c /tmp/cca00097.iGNU CPP version 2.7.0 (i386 Linux/ELF)#include "..." search starts here:#include <...> search starts here: /usr/local/include /usr/i486-linux/include /usr/lib/gcc-lib/i486-linux/2.7.0/include /usr/includeEnd of search list. /usr/lib/gcc-lib/i486-linux/2.7.0/cc1 /tmp/cca00097.i -fno-strength-reduce -quiet -dumpbase mat.c -version -o /tmp/cca00097.sGNU C version 2.7.0 (i386 Linux/ELF) compiled by GNU C version 2.7.0. /usr/i486-linux/bin/as -V -Qy -o /tmp/cca000971.o /tmp/cca00097.sGNU assembler version cygnus/linux-2.5.2l.15 (i486-linux), using BFD version cygnus/linux-2.5.2l.11 /usr/i486-linux/bin/ld -m elf_i386 -dynamic-linker /lib/ld-linux.so.1 /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/crtbegin.o -L/usr/lib/gcc-lib/i486-linux/2.7.0 -L/usr/i486-linux/lib /tmp/cca000971.o -lgcc -lc -lgcc /usr/lib/crtend.o /usr/lib/crtn.o/tmp/cca000971.o(.text+0xf): undefined reference to `PASCAL_MAIN'/tmp/cca000971.o(.text+0x39): undefined reference to `exp' =========================== The only apparent difference between both results is in the libraries ( I think) Can anyone help me, please ??? Thanks in advance.
Re: problems with GCC
Author: Toby K Hay
Date: Wed, 17 Apr 1996 03:42
Date: Wed, 17 Apr 1996 03:42
16 lines
1249 bytes
1249 bytes
Chano GĂłmez MartĂnez (chano@ran.es) wrote: : First of all, I want to apologize for my awful English. : I'm trying to port a C program from Borland C++ 3.1 to GCC under : Linux. : My problem is that I can't use any function from math.h !!! : The file is correctly #include'd ( in fact, I get no compilation : errors ) but the linker always tells me something like : snip Your English is impeccable. I expect your only problem with gcc is that you've neglected to link the math library by typing -lm when you invoke gcc. I use cc to compile and link my ANSI C programs developed in Turbo C 3.1 with the following command: cc MyProg.c -lm -O I expect gcc is the same. Toby Hay thay@uoguelph.ca
Re: problems with GCC
Author: Thomas H. Robey
Date: Wed, 17 Apr 1996 13:41
Date: Wed, 17 Apr 1996 13:41
14 lines
1013 bytes
1013 bytes
In article <4l1and$iql@news.ran.es>, chano@ran.es (Chano GĂłmez MartĂnez) wrote: -First of all, I want to apologize for my awful English. - -Now, the C stuff : - -I'm trying to port a C program from Borland C++ 3.1 to GCC under -Linux. -My problem is that I can't use any function from math.h !!! Try -lm on the link line. The problem is that libm.a (the math library) is not being linked into your program, so no math functions are resolved. You may also have to tell the linker where libm.a is located if it isn't in one of the standard places.
Re: problems with GCC
Author: Tom Watson
Date: Wed, 17 Apr 1996 19:30
Date: Wed, 17 Apr 1996 19:30
35 lines
1755 bytes
1755 bytes
In article <4l1and$iql@news.ran.es>, chano@ran.es (Chano GĂłmez MartĂnez) wrote: > First of all, I want to apologize for my awful English. > > Now, the C stuff : > > I'm trying to port a C program from Borland C++ 3.1 to GCC under > Linux. > My problem is that I can't use any function from math.h !!! > The file is correctly #include'd ( in fact, I get no compilation > errors ) but the linker always tells me something like : > > /tmp/cca000971.o(.text+0x39): undefined reference to `exp' > > The funny thing is that GPC ( the GNU Pascal compiler ) allows me to > use math.h functions lihe exp(), sin(), fabs(), etc, but when I > convert my Pascal programs to C with p2c and try to compile them with > GCC , I get the same error again. > <<<deletia regarding GPC and gcc>>> > > The only apparent difference between both results is in the libraries > ( I think) > Can anyone help me, please ??? > Yes, the difference is in the libraries. To use exp, sin, ... you need to include '-lm' (at least on your system) in the invoking 'gcc' line. The GPC thing had it already included. Most functions in <math.h> need the '-lm' addition if compiled under a Unix style compiler. This is probably an FAQ! (see the C faq's on the friendly 'rtfm' server). -- Tom Watson tsw@3do.com (Home: tsw@johana.com)
Re: problems with GCC
Author: Glenn Lamb
Date: Wed, 17 Apr 1996 20:15
Date: Wed, 17 Apr 1996 20:15
20 lines
1124 bytes
1124 bytes
Chano GĂłmez MartĂnez wrote: > [snip] > > /tmp/cca000971.o(.text+0x39): undefined reference to `exp' > > The funny thing is that GPC ( the GNU Pascal compiler ) allows me to > use math.h functions lihe exp(), sin(), fabs(), etc, but when I > convert my Pascal programs to C with p2c and try to compile them with > GCC , I get the same error again. are you linking in the math library? $ gcc file.c -o file -lm [snip] -- Glenn Lamb System's Administrator glenn@sec.sel.sony.com
Re: problems with GCC
Author: Juniet Christophe
Date: Sat, 20 Apr 1996 11:33
Date: Sat, 20 Apr 1996 11:33
60 lines
2252 bytes
2252 bytes
Chano GĂłmez MartĂnez wrote: > > First of all, I want to apologize for my awful English. I should say the same ;^) > Now, the C stuff : > > I'm trying to port a C program from Borland C++ 3.1 to GCC under > Linux. > My problem is that I can't use any function from math.h !!! > The file is correctly #include'd ( in fact, I get no compilation > errors ) but the linker always tells me something like : > > /tmp/cca000971.o(.text+0x39): undefined reference to `exp' > > The funny thing is that GPC ( the GNU Pascal compiler ) allows me to > use math.h functions lihe exp(), sin(), fabs(), etc, but when I > convert my Pascal programs to C with p2c and try to compile them with > GCC , I get the same error again. > > Here is the result from compiling the Pascal source with GPC -v ... > ================================================ > (...messages from gpc...) > -L/usr/i486-linux/lib /tmp/cca001031.o -lgpc -lgcc -lm -lc -lg Here it is! ^^^^^^ (...messages from gcc...) > > The only apparent difference between both results is in the libraries > ( I think) > Can anyone help me, please ??? > When you compile some code, you need to link it to the right libraries. For instance, you need to link your program with the library libm which is for math. Try `gcc ... -lm`. In general, for foo.h try -lfoo, but you'd better check /lib or /usr/lib. > Thanks in advance. Hope this helps :) -- Christophe Juniet chris@lmm.com Un Linux, s'il vous plaĂŽt! (A Linux, please!)
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads