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-17-2008, 02:32 PM
John Salmon
 
Default Problem compiling simple C program

"Joost Witteveen" <joosteto@gmail.com> wrote in
news:ajhhp-1Nx-29@gated-at.bofh.it:

> 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.
>
>

Of Cource! I'm an old dog learning new tricks. Yhanks all for
understanding.

--
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
 

Thread Tools




All times are GMT. The time now is 07:00 AM.

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