?
Solved

Problem with #include<math.h>

Posted on 1999-01-19
4
Medium Priority
?
420 Views
Last Modified: 2013-11-18
In two instances, i have compiled programs using the
math.h and string.h files, only to get the following error:

(for math.h)

ld: 0711-317 ERROR: undefined symbol: .sqrt
ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more info.

I am compiling on AIX.

The header files are where they ought to be.  I can include
stdio.h, from the same directory, without any problems.

a: what might be the cause?
b: can i link these header files in through a different method?

even this simple test will generate the above error

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

main()
{
    printf("%f", sqrt(10.0));
}


Using string.h in a similar simple test generates the same
errors.
0
Comment
Question by:rhigg
4 Comments
 

Expert Comment

by:jji
ID: 1258179
If you use math.h you must use '-lm' switch with c89 (or whatever is your compiler).
  'c89 foo.c -o test -lm'
0
 
LVL 3

Accepted Solution

by:
mliberi earned 150 total points
ID: 1258180
The problem you experienced is not a compiler problem, but a linker one.

The statement #include <math.h> simply tells the C compiler to source the file that contains FUNCTION DEFINITIONS and not function CODE.

The code for all mathematical functions has been placed in /usr/lib/libm.a.

You must tell the compiler to get the code from that file by specifying -lm option, generally  speaking -lxxx options tells the compiler to link libxxx.a library.

to compile your program use: cc -o foo -lm foo.c
0
 

Author Comment

by:rhigg
ID: 1258181
Both responses work for me.  What is the difference in this forum between a comment (jji) and an answer?(mliberi).

In other words, whats the criteria for assigning the points to the response?


0
 
LVL 85

Expert Comment

by:ozo
ID: 1258182
You can only assign points to the "answer", but you can post another question to assign additional points to another person.
If you prefer to assign the points to jji, you can reject the proposed answer, and ask jji to resubmit an answer.
Or, you can post a question in Customer Support to ask linda to help you split the points.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question