Solved

Problem with #include<math.h>

Posted on 1999-01-19
4
401 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 50 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 84

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

829 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