Undefined reference to 'sin' Solution

Source: Internet
Author: User
Zhanhailiang Date:

When using GCC to compile the following code, "undefined reference to 'sin'" is reported '":

#include <stdio.h>#include <math.h>#include <stdlib.h> main () {    double a = sin(1);    exit (0);}
[root@~/wade/codeReview/learningc/9]# gcc -o timetest timetest.c /tmp/ccIzIHF7.o: In function `func‘:timetest.c:(.text+0x3f): undefined reference to `sin‘collect2: ld returned 1 exit status

This is generally due to the lack of a mathematical library. You only need to manually add the GCC libm. So library during compilation, as shown below:

[root@~/wade/codeReview/learningc/9]# gcc timetest.c -lm -o timetest[root@~/wade/codeReview/learningc/9]# ./timetest

Specify the path of the corresponding library through-L. The default path is the path of the system library, such as/lib and/usr/lib64 (64-bit )(This default system library path value will be modified after confirmation by the authorIn Linux, the Unified Library naming rules are lib ***. So. Therefore,-LM indicates that GCC will go to the system library path by default to find the libm. So library, as shown below:

[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' Solution

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.