?
Solved

Problem with #include<math.h>

Posted on 1999-01-19
4
Medium Priority
?
408 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

770 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