FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Debian > Debian User

 
 
LinkBack Thread Tools
 
Old 04-15-2008, 06:39 PM
John Salmon
 
Default Problem compiling simple C program

I'm running Debian Etch on a PC. When I try to compile the following
(called test.c);

#include <math.h>
#include <stdio.h>

int main()
{
double
val = 1.55;

printf("sine: %g
", sin(val));

return 0;
}

using the command line

gcc -Wall -o test test.c

I get

/tmp/cciDV02m.o: In function `main':
test.c.text+0x21): undefined reference to `sin'
collect2: ld returned 1 exit status

When I compile the equivalent C++ program using the apropriate C++
parameters, everything goes great. Have I neglected to load a Debian
package? Any help will be appreciated.
--
John Salmon
salmonjj@comcast.net
---- Posted via Pronews.com - Premium Corporate Usenet News Provider ----
http://www.pronews.com offers corporate packages that have access to 100,000+ newsgroups


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 04-15-2008, 07:11 PM
Sven Joachim
 
Default Problem compiling simple C program

On 2008-04-15 20:39 +0200, John Salmon wrote:

> I'm running Debian Etch on a PC. When I try to compile the following
> (called test.c);
>
> #include <math.h>
> #include <stdio.h>
>
> int main()
> {
> double
> val = 1.55;
>
> printf("sine: %g
", sin(val));
>
> return 0;
> }
>
> using the command line
>
> gcc -Wall -o test test.c
>
> I get
>
> /tmp/cciDV02m.o: In function `main':
> test.c.text+0x21): undefined reference to `sin'
> collect2: ld returned 1 exit status

You need to link to the math library by specifying -lm _at the end_ of
the gcc command line, otherwise the linker does not know about the sin()
function.

> When I compile the equivalent C++ program using the apropriate C++
> parameters, everything goes great. Have I neglected to load a Debian
> package? Any help will be appreciated.

That is to be expected, because C++ programs are automatically linked
against the math library. In C you have to tell the linker to use it
with -lm.

Sven


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 04-15-2008, 07:14 PM
"Sergio Cuéllar Valdés"
 
Default Problem compiling simple C program

2008/4/15, John Salmon <salmonjj@comcast.net>:
> I'm running Debian Etch on a PC. When I try to compile the following
> (called test.c);
>
> #include <math.h>
> #include <stdio.h>
>
> int main()
> {
> double
> val = 1.55;
>
> printf("sine: %g
", sin(val));
>
> return 0;
> }
>
> using the command line
>
> gcc -Wall -o test test.c
>
> I get
>
> /tmp/cciDV02m.o: In function `main':
> test.c.text+0x21): undefined reference to `sin'
> collect2: ld returned 1 exit status
>
> When I compile the equivalent C++ program using the apropriate C++
> parameters, everything goes great. Have I neglected to load a Debian
> package? Any help will be appreciated.

Use the -lm flag

Regards,
Sergio Cuellar

--
"Meine Hoffnung soll mich leiten
Durch die Tage ohne Dich
Und die Liebe soll mich tragen
Wenn der Schmerz die Hoffnung bricht"


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 04-16-2008, 02:29 PM
John Salmon
 
Default Problem compiling simple C program

Sven Joachim <svenjoac@gmx.de> wrote in news:aiYRm-2Tc-23@gated-at.bofh.it:

> On 2008-04-15 20:39 +0200, John Salmon wrote:
>
>> I'm running Debian Etch on a PC. When I try to compile the following
>> (called test.c);
>>
>> #include <math.h>
>> #include <stdio.h>
>>
>> int main()
>> {
>> double
>> val = 1.55;
>>
>> printf("sine: %g
", sin(val));
>>
>> return 0;
>> }
>>
>> using the command line
>>
>> gcc -Wall -o test test.c
>>
>> I get
>>
>> /tmp/cciDV02m.o: In function `main':
>> test.c.text+0x21): undefined reference to `sin'
>> collect2: ld returned 1 exit status
>
> You need to link to the math library by specifying -lm _at the end_ of
> the gcc command line, otherwise the linker does not know about the sin()
> function.
>
>> When I compile the equivalent C++ program using the apropriate C++
>> parameters, everything goes great. Have I neglected to load a Debian
>> package? Any help will be appreciated.
>
> That is to be expected, because C++ programs are automatically linked
> against the math library. In C you have to tell the linker to use it
> with -lm.
>
> Sven
>
>

That solved the linking problem. Now, after a successful compilation, when
I run 'test' I gen no output. ???

--
John Salmon
salmonjj@comcast.net
---- Posted via Pronews.com - Premium Corporate Usenet News Provider ----
http://www.pronews.com offers corporate packages that have access to 100,000+ newsgroups


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 04-16-2008, 02:54 PM
"Joost Witteveen"
 
Default Problem compiling simple C program

On 16/04/2008, John Salmon <salmonjj@comcast.net> wrote:
> Sven Joachim <svenjoac@gmx.de> wrote in news:aiYRm-2Tc-23@gated-at.bofh.it:
>
>
> > On 2008-04-15 20:39 +0200, John Salmon wrote:
> >
> >> I'm running Debian Etch on a PC. When I try to compile the following
> >> (called test.c);
> >>
> >> #include <math.h>
> >> #include <stdio.h>
> >>
> >> int main()
> >> {
> >> double
> >> val = 1.55;
> >>
> >> printf("sine: %g
", sin(val));
> >>
> >> return 0;
> >> }
> >>
> >> using the command line
> >>
> >> gcc -Wall -o test test.c
> >>
> >> I get
> >>
> >> /tmp/cciDV02m.o: In function `main':
> >> test.c.text+0x21): undefined reference to `sin'
> >> collect2: ld returned 1 exit status
> >
> > You need to link to the math library by specifying -lm _at the end_ of
> > the gcc command line, otherwise the linker does not know about the sin()
> > function.
> >
> >> When I compile the equivalent C++ program using the apropriate C++
> >> parameters, everything goes great. Have I neglected to load a Debian
> >> package? Any help will be appreciated.
> >
> > That is to be expected, because C++ programs are automatically linked
> > against the math library. In C you have to tell the linker to use it
> > with -lm.
> >
> > Sven
> >
> >
>
>
> That solved the linking problem. Now, after a successful compilation, when
> I run 'test' I gen no output. ???


"test" is a bash-builtin, and is a executable in /usr/bin/test, so
that is what you were running.
You can run your "test" command by typing
./test
or rename it to something else.


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 04-16-2008, 03:05 PM
Kamaraju S Kusumanchi
 
Default Problem compiling simple C program

John Salmon wrote:

> That solved the linking problem. Now, after a successful compilation, when
> I run 'test' I gen no output. ???
>

It works for me.

$cat using_sin.c
#include <stdio.h>
#include <math.h>

int main()
{
double val = 1.55;
printf("sine: %g
", sin(val));
return 0;
}

$gcc using_sin.c -lm -o using_sin

$./using_sin
sine: 0.999784

I am using Debian Etch + some packages from Lenny, gcc 4.2.3-2

hth
raju
--
Kamaraju S Kusumanchi
http://www.people.cornell.edu/pages/kk288/
http://malayamaarutham.blogspot.com/


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 04-16-2008, 03:10 PM
"H.S."
 
Default Problem compiling simple C program

John Salmon wrote:

Sven Joachim <svenjoac@gmx.de> wrote in news:aiYRm-2Tc-23@gated-at.bofh.it:


On 2008-04-15 20:39 +0200, John Salmon wrote:

I'm running Debian Etch on a PC. When I try to compile the following
(called test.c);


#include <math.h>
#include <stdio.h>

int main()
{
double
val = 1.55;

printf("sine: %g
", sin(val));

return 0;
}

using the command line

gcc -Wall -o test test.c

I get

/tmp/cciDV02m.o: In function `main':
test.c.text+0x21): undefined reference to `sin'
collect2: ld returned 1 exit status

You need to link to the math library by specifying -lm _at the end_ of
the gcc command line, otherwise the linker does not know about the sin()
function.

When I compile the equivalent C++ program using the apropriate C++
parameters, everything goes great. Have I neglected to load a Debian
package? Any help will be appreciated.

That is to be expected, because C++ programs are automatically linked
against the math library. In C you have to tell the linker to use it
with -lm.

Sven




That solved the linking problem. Now, after a successful compilation, when
I run 'test' I gen no output. ???




In the directory where you source and output executable is, try "./test".

You are not getting any output probably because you are inadvertently
using the system "test" command.


To avoid such introduction traps, I usually make such example programs
with names quite different from any commands that the system may have,
for example by using my initials or by using a number in the source
file. Using "mytest" or "example1" would have been a better choice in
your case.


->HS


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 04-16-2008, 07:39 PM
Ron Johnson
 
Default Problem compiling simple C program

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1



Thanks all for bottom-posting! But why isn't anyone snipping out
the same, repeating, unnecessary text?

On 04/16/08 10:10, H.S. wrote:
> John Salmon wrote:
>> Sven Joachim <svenjoac@gmx.de> wrote in
>> news:aiYRm-2Tc-23@gated-at.bofh.it:
>>
>>> On 2008-04-15 20:39 +0200, John Salmon wrote:
>>>
>>>> I'm running Debian Etch on a PC. When I try to compile the following
>>>> (called test.c);
>>>>
>>>> #include <math.h>
>>>> #include <stdio.h>
>>>>
>>>> int main()
>>>> {
>>>> double
>>>> val = 1.55;
>>>>
>>>> printf("sine: %g
", sin(val));
>>>>
>>>> return 0;
>>>> }
>>>>
>>>> using the command line
>>>>
>>>> gcc -Wall -o test test.c
>>>>
>>>> I get
>>>>
>>>> /tmp/cciDV02m.o: In function `main':
>>>> test.c.text+0x21): undefined reference to `sin'
>>>> collect2: ld returned 1 exit status
>>> You need to link to the math library by specifying -lm _at the end_ of
>>> the gcc command line, otherwise the linker does not know about the sin()
>>> function.
>>>
>>>> When I compile the equivalent C++ program using the apropriate C++
>>>> parameters, everything goes great. Have I neglected to load a Debian
>>>> package? Any help will be appreciated.
>>> That is to be expected, because C++ programs are automatically linked
>>> against the math library. In C you have to tell the linker to use it
>>> with -lm.
>>>
>>> Sven
>>>
>>>
>>
>> That solved the linking problem. Now, after a successful compilation,
>> when I run 'test' I gen no output. ???
>>
>
> In the directory where you source and output executable is, try "./test".
>
> You are not getting any output probably because you are inadvertently
> using the system "test" command.
>
> To avoid such introduction traps, I usually make such example programs
> with names quite different from any commands that the system may have,
> for example by using my initials or by using a number in the source
> file. Using "mytest" or "example1" would have been a better choice in
> your case.

- --
Ron Johnson, Jr.
Jefferson LA USA

We want... a Shrubbery!!
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFIBlXmS9HxQb37XmcRAjZHAKDMzYLjX3JH68Qm4UOdLI Wop2UmkQCeJusw
0PDbdYFU1Qqs9vL2VOxI/z8=
=5DqE
-----END PGP SIGNATURE-----


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 04-17-2008, 01:06 AM
"s. keeling"
 
Default Problem compiling simple C program

Ron Johnson <ron.l.johnson@cox.net>:
>
> Thanks all for bottom-posting! But why isn't anyone snipping out
> the same, repeating, unnecessary text?
>
> On 04/16/08 10:10, H.S. wrote:
> > John Salmon wrote:
> >> Sven Joachim <svenjoac@gmx.de> wrote in
> >> news:aiYRm-2Tc-23@gated-at.bofh.it:
> >>
> >>> On 2008-04-15 20:39 +0200, John Salmon wrote:
> >>>
> >>>> I'm running Debian Etch on a PC. When I try to compile the following
> >>>> (called test.c);

Well, so did you. Heal thyself. :-)


--
Any technology distinguishable from magic is insufficiently advanced.
(*) http://blinkynet.net/comp/uip5.html Linux Counter #80292
- - http://www.faqs.org/rfcs/rfc1855.html Please, don't Cc: me.


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 04-17-2008, 03:29 AM
Ron Johnson
 
Default Problem compiling simple C program

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 04/16/08 20:06, s. keeling wrote:
> Ron Johnson <ron.l.johnson@cox.net>:
>> Thanks all for bottom-posting! But why isn't anyone snipping out
>> the same, repeating, unnecessary text?
>>
>> On 04/16/08 10:10, H.S. wrote:
>>> John Salmon wrote:
>>>> Sven Joachim <svenjoac@gmx.de> wrote in
>>>> news:aiYRm-2Tc-23@gated-at.bofh.it:
>>>>
>>>>> On 2008-04-15 20:39 +0200, John Salmon wrote:
>>>>>
>>>>>> I'm running Debian Etch on a PC. When I try to compile the following
>>>>>> (called test.c);
>
> Well, so did you. Heal thyself. :-)

If I snip out the offending text, how could I demonstrate the
un-netiquette? Akin to medical students not being able to dissect
cadavers to see what tumors look like...

- --
Ron Johnson, Jr.
Jefferson LA USA

We want... a Shrubbery!!
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFIBsQfS9HxQb37XmcRAnMEAKDVTzfaNI/Gk7V7ir7tWjwMCLR3pgCgxe/v
0gEq8Vk7urFICFB+xQ7W+f0=
=uZJ7
-----END PGP SIGNATURE-----


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 

Thread Tools




All times are GMT. The time now is 04:02 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2007 - 2008, www.linux-archive.org