Re: C Program compile error

2002-02-22 Thread Ben Logan

On Fri, Feb 22, 2002 at 07:16:12AM -0700, Frank Carreiro wrote:
> Is there a list someone can suggest I join?  Looking for one that can 
> help answer these kind of questions :-)

Somewhere out there there's a list called linux-c-programming...I
think it's one of the mailing lists pointed to on kernel.org (not
sure, though).  A Google search would surely turn it up.  I was on it
for awhile, and will probably rejoin it soon, as it was very helpful.

Regards,
Ben

-- 
Ben Logan: ben at wblogan dot net
OpenPGP Key KeyID: A1ADD1F0



___
Redhat-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list



Re: C Program compile error

2002-02-22 Thread Frank Carreiro

>
>
>
>A bit more explanation--although this isn't specifically RedHat, or even
>Linux, so it should be on a software development list...so the following
>is necessarily simplified.  But it should dispell some misconceptions I
>think I see.
>

Is there a list someone can suggest I join?  Looking for one that can 
help answer these kind of questions :-)

[snip]

>
>
>That's about as simplified as I can make it, but I hope it helps.
> -- 
> Dave Ihnat
> [EMAIL PROTECTED]
>

Yes Definitely!  I appreciate the comments from everyone.

Thanks All!

Frank




___
Redhat-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list



Re: C Program compile error

2002-02-21 Thread Statux

# gcc -o program code.c -lm

Make sure you're remembering to include the library at compile time. The 
math functions are not part of the standard C library :)

On Thu, 21 Feb 2002, Frank Carreiro wrote:

> Not sure if this is the right list for it but here goes...
> 
> I'm currently learning how to code in C.  I'm using a RedHat 7.1 
> workstation which when installed I selected to install everything (I 
> don't like messing with dependancies ::grinz::).  I've been including 
> stdio.h and the last few weeks everything has been happy.  The last 
> couple of days I've been learning about math.h however it's failing when 
> I try and compile.  Getting the following message:
> 
> ---
> 
> In function `main`:
> undefined reference to `pow`
> collect2: ld returned 1 exit status
> 
> ---
> 
> I'm trying to calculate a value (x) raised to the y power.  I suspect 
> there is a library not found by the linker (wild guess).
> 
> Any thoughts on how I can track this down?
> 
> Thx
> 
> 
> 
> 
> 
> ___
> Redhat-list mailing list
> [EMAIL PROTECTED]
> https://listman.redhat.com/mailman/listinfo/redhat-list
> 

-- 
-Statux



___
Redhat-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list



Re: C Program compile error

2002-02-21 Thread Dave Ihnat

On Thu, Feb 21, 2002 at 02:57:58PM -0500, Trond Eivind Glomsrød wrote:
> No, it only declares the symbols and functions. A header file does not
> specify linking.
> 
> > Out of curiosity is there a way to compile without specifying -lm?
> > 
> > Just wondering why -lm is required for standard math functions.
> 
> Because libm contains the standard math functions.

A bit more explanation--although this isn't specifically RedHat, or even
Linux, so it should be on a software development list...so the following
is necessarily simplified.  But it should dispell some misconceptions I
think I see.

A program consists of code that is compiled from source into machine
executable instructions.  If you had to rebuild all source every time you
tried to build the program, the development process would be exceedingly
time-consuming and tedious; and usually, changes are only to a small
portion of the code at any given time.  Therefore, it's desirable to do
this in stages.

Thus, it's possible to compile portions--usually segregated in separate
source files--of the program into an intermediate form called an object
file.  A program called the 'linker' then can combine these intermediate
object files into a functioning executable file.  When components of the
program are separated in this manner, header files provide information
about the other portions of the program--such as valid function names,
values for arguments, etc.--that need to be used to reference these in
the source of any given element.  The intermediate object files contain
these _external_ references in a form recognizable to the 'linker', which
can then reconcile them all when it constructs the final executable.

Much code is common--for instance, math functions--and doesn't change
between different programs that use it.  Thus, common functions are
compiled into intermediate object form, and the resulting files are
grouped together in an object library for convenience.  The linker knows
how to select just the objects it needs from the library.

That's about as simplified as I can make it, but I hope it helps.
-- 
Dave Ihnat
[EMAIL PROTECTED]



___
Redhat-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list



C Program compile error

2002-02-21 Thread Frank Carreiro

Not sure if this is the right list for it but here goes...

I'm currently learning how to code in C.  I'm using a RedHat 7.1 
workstation which when installed I selected to install everything (I 
don't like messing with dependancies ::grinz::).  I've been including 
stdio.h and the last few weeks everything has been happy.  The last 
couple of days I've been learning about math.h however it's failing when 
I try and compile.  Getting the following message:

---

In function `main`:
undefined reference to `pow`
collect2: ld returned 1 exit status

---

I'm trying to calculate a value (x) raised to the y power.  I suspect 
there is a library not found by the linker (wild guess).

Any thoughts on how I can track this down?

Thx





___
Redhat-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list



Re: C Program compile error

2002-02-21 Thread Trond Eivind Glomsrød

Frank Carreiro <[EMAIL PROTECTED]> writes:

> That worked thanks :-)
> 
> I've read through the gcc man page and didn't see the -lm option.  In
> my source as I understand it #include  should have done it.

No, it only declares the symbols and functions. A header file does not
specify linking.


> Out of curiosity is there a way to compile without specifying -lm?
> 
> Just wondering why -lm is required for standard math functions.

Because libm contains the standard math functions.

-- 
Trond Eivind Glomsrød
Red Hat, Inc.



___
Redhat-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list



Re: C Program compile error

2002-02-21 Thread Frank Carreiro



That worked thanks :-)

I've read through the gcc man page and didn't see the -lm option.  In my 
source as I understand it #include  should have done it.  Out of 
curiosity is there a way to compile without specifying -lm?

Just wondering why -lm is required for standard math functions.

Thanks again!

Frank


Frank Carreiro <[EMAIL PROTECTED]> writes:

[snip]

>> 
>> ---
>> 
>> In function `main`:
>> undefined reference to `pow`
>> collect2: ld returned 1 exit status
>> 
>> ---
>> 
>> I'm trying to calculate a value (x) raised to the y power.  I suspect
>> there is a library not found by the linker (wild guess).
>> 
>> Any thoughts on how I can track this down?
>

"-lm" (link with the standard math library)

-- Trond Eivind Glomsrød Red Hat, Inc.




___
Redhat-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list



Re: C Program compile error

2002-02-21 Thread Trond Eivind Glomsrød

Frank Carreiro <[EMAIL PROTECTED]> writes:

> Not sure if this is the right list for it but here goes...
> 
> I'm currently learning how to code in C.  I'm using a RedHat 7.1
> workstation which when installed I selected to install everything (I
> don't like messing with dependancies ::grinz::).  I've been including
> stdio.h and the last few weeks everything has been happy.  The last
> couple of days I've been learning about math.h however it's failing
> when I try and compile.  Getting the following message:
> 
> ---
> 
> In function `main`:
> undefined reference to `pow`
> collect2: ld returned 1 exit status
> 
> ---
> 
> I'm trying to calculate a value (x) raised to the y power.  I suspect
> there is a library not found by the linker (wild guess).
> 
> Any thoughts on how I can track this down?

"-lm" (link with the standard math library)

-- 
Trond Eivind Glomsrød
Red Hat, Inc.



___
Redhat-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list



Re: C Program compile error

2002-02-21 Thread Jim Hayward

On Thu, 21 Feb 2002 11:17:40 -0700
Frank Carreiro <[EMAIL PROTECTED]> wrote:

> I try and compile.  Getting the following message:
> 
> ---
> 
> In function `main`:
> undefined reference to `pow`
> collect2: ld returned 1 exit status
> 
> ---
> 
> I'm trying to calculate a value (x) raised to the y power.  I suspect 
> there is a library not found by the linker (wild guess).
> 
> Any thoughts on how I can track this down?
> 
> Thx

$ apropos pow
README.machten [perlmachten] (1)  - Perl version 5 on Power MachTen systems
apm  (1)  - query Advanced Power Management (APM) BIOS
apmd (8)  - Advanced Power Management (APM) daemon
exp  (3)  - exponential, logarithmic and power functions
ldexp(3)  - multiply floating-point number by integral power of 2
log [exp](3)  - exponential, logarithmic and power functions
log10 [exp]  (3)  - exponential, logarithmic and power functions
pow [exp](3)  - exponential, logarithmic and power functions
poweroff [halt]  (8)  - stop the system

Then look at the manpage for the pow function

>From the manpage

EXP(3)  Linux Programmer's Manual  EXP(3)

NAME
   exp, log, log10, pow - exponential, logarithmic and power functions

SYNOPSIS
   #include 


The pow function is in math.h

Regards,
Jim H


msg72484/pgp0.pgp
Description: PGP signature