1. ## Two questions: GCC

Hi all!

This is probably simple stuff... but I can't seem to find it (yes I googled the heck out of it).

OK, Ques #1: In Linux and using GCC, how do I determine which library has the function I need?

Ques #2: I need to do base 10 exponent (that is, 10^0=1, 10^1=10, 10^2=100, etc...) how do I do it in GCC?

In Win LCC-32 there is a function "pow10()" which takes 1 parameter (the exponent). For example, "pow10(3) == 1000".

Anything like this in GCC, or do I have to write my own?

Thanks!

-- Roger

2. ## Re: Two questions: GCC

First off, GCC is a C compiler. glibc is the GNU C Standard Library, which is what you meant by GCC.

Originally Posted by Krupski
OK, Ques #1: In Linux and using GCC, how do I determine which library has the function I need?
You need to know what library a function is in before you can use it.

Originally Posted by Krupski
Ques #2: I need to do base 10 exponent (that is, 10^0=1, 10^1=10, 10^2=100, etc...) how do I do it in GCC?

In Win LCC-32 there is a function "pow10()" which takes 1 parameter (the exponent). For example, "pow10(3) == 1000".

Anything like this in GCC, or do I have to write my own?
You're getting confused between GCC and glibc, see above.

Anyway, glibc has the function pow10 (the documentation says that exp10 is preferred), which takes a double and returns a double. Include <math.h>, and add "-lm" to the GCC command.

3. ## Re: Two questions: GCC

Originally Posted by bruce89
Anyway, glibc has the function pow10 (the documentation says that exp10 is preferred), which takes a double and returns a double. Include <math.h>, and add "-lm" to the GCC command.
I have done both (include math.h and use the -lm switch) and here's what I get:

Code:
```convert.c: In function ‘main’:
convert.c:73: warning: implicit declaration of function ‘pow10’
convert.c:73: warning: incompatible implicit declaration of built-in function ‘pow10’```
I get the same exact error with "exp10" - no difference.

Concerning my first question, if I *didn't* know that "pow10()" needed "math.h", how would I go about finding which "include" to use?

I saw the answer on here somewhere before... but I don't remember what it was and I can't find it.

4. ## Re: Two questions: GCC

Code:
`pow(10, 3);`
http://www.cplusplus.com/reference/clibrary/cmath/
(Yeah, it's a c++ reference, but the C library is intact!)
Last edited by Can+~; February 17th, 2009 at 03:36 AM.

5. ## Re: Two questions: GCC

Originally Posted by Can+~
Code:
`pow(10, 3);`
http://www.cplusplus.com/reference/clibrary/cmath/
(Yeah, it's a c++ reference, but the C library is intact!)
Well now that works! Thank you so much.

-- Roger

(edit to add): Thanks for the link to the reference too! It'll be a great help.
Last edited by Krupski; February 17th, 2009 at 05:33 AM.

6. Way Too Much Ubuntu
Join Date
May 2007
Beans
251

## Re: Two questions: GCC

Originally Posted by Krupski
Concerning my first question, if I *didn't* know that "pow10()" needed "math.h", how would I go about finding which "include" to use?

I saw the answer on here somewhere before... but I don't remember what it was and I can't find it.
You generally use manual pages to see how to use the function - what headers to include and what libraries to link to.
For example, all the glibc functions are documented in the 3rd section of manual pages. So, you could do:
Code:
`man 3 pow`
You need to have the 'manpages' package installed for that.

7. ## Re: Two questions: GCC

Originally Posted by the_unforgiven
You generally use manual pages to see how to use the function - what headers to include and what libraries to link to.
For example, all the glibc functions are documented in the 3rd section of manual pages. So, you could do:
Code:
`man 3 pow`
You need to have the 'manpages' package installed for that.
Thank you for the info. I'll have to install the manpages package... don't have it yet.

Thanks!

-- Roger

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•