Undefined reference to ' sin& #39; problem solving

Source: Internet
Author: User

  Zhanhailiang Date: 2014-10-25

Use GCC to compile such as the following code times "undefined reference to ' sin '":

#include <stdio.h>#include <math.h>#include <stdlib.h>Main() {    DoubleA= Sin(1);    Exit (0);}
[Root@~/Wade/Codereview/Learningc/9]# gcc-o Timetest timetest.c/Tmp/Ccizihf7.o:infunction `Func': timetest.c: (. text+0x3f): Undefined reference to ' sin 'Collect2:LDReturned1 ExitStatus

Usually due to the lack of a mathematical library, only need to manually add the GCC libm.so Library at compile time. For example, the following:

[Root@~/Wade/Codereview/Learningc/9]# gcc Timetest.c-lm-o timetest[Root@~/Wade/Codereview/Learningc/9]#./timetest

, by specifying the path of the corresponding library through-l, it defaults to the system library path, such as/lib and/USR/LIB64 (64-bit) ( this default system library path value to be confirmed by the author and then change ), Linux Library Unified naming specification is lib***.so, Therefore,-LM indicates that GCC defaults to the system library path and goes down to the libm.so library, such as the following:

[Root@/Usr/Lib64]# find/usr/lib64/|grep "libm.so"/Usr/Lib64/Libm.so[Root@/Usr/Lib64]# find/lib |grep "libm.so"

Undefined reference to ' sin& #39; problem solving

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.