lotus



previous page: 107. Why Are My Programs So Large?
  
page up: Linux FAQ
  
next page: 109. How To Program XYZ Under Linux

108. How To Prevent Errors when Linking Programs with Math Functions




Description

This article is from the Frequently Asked Questions for Linux, the Free/Open Source UNIX-like operating system kernel that runs on many modern computer systems. Maintained by David C. Merrill with numerous contributions by others. (v1.0).

108. How To Prevent Errors when Linking Programs with Math Functions

A: Older run-time libraries included the math library in the C run-time library. It was not necessary to specify the math library separately when compiling. If the compiler generates a message like this when linking a program that uses math functions:

 /tmp/ccDUQM4J.o: In function "main":                                        
 /tmp/ccDUQM4J.o(.text+0x19): undefined reference to "sqrt"                  
 collect2: ld returned 1 exit status                                         

You need use the -lm option with GCC to link with the math libraries:

 # gcc -o program program.c -lm                                              

Make sure also to use the statement #include <math.h> in the source file.

[Florian Schmidt]

 

Continue to:















TOP
previous page: 107. Why Are My Programs So Large?
  
page up: Linux FAQ
  
next page: 109. How To Program XYZ Under Linux