Solution to program errors using math library functions compiled with gcc in Linux
Source: Internet
Author: User
Solution to program errors using math library functions compiled with gcc in Linux-Linux general technology-Linux programming and kernel information. For more information, see the following. Symptoms:
When the math library function is used in the c program and compiled into obj, an error similar to the following occurs when the execution file is generated:
/Tmp/ccalvMPY. o: In function 'main ':
/Tmp/ccalvMPY. o (. text + 0x40): undefined reference to 'pow'
Cause:
In linux, the pow function is defined in libm. so, unlike DevC ++ or TC, which is stored in/lib in C language. C. When the connection fails, find the corresponding library to connect.
Solution:
The compiler has some common parameters, in which-l is used to identify the library information to be linked:
-Lm indicates that the math library libm. a or libm. so or libm. sl needs to be linked.
Use the following compilation command to tell the location of the math library.
Gcc filename. c-lm
Or
Gcc filename. c-lm-L/lib-L/usr/lib
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.