Solved

Problem with #include<math.h>

Posted on 1999-01-19
4
391 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
Comment Utility
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 50 total points
Comment Utility
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
Comment Utility
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 84

Expert Comment

by:ozo
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
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.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now