gcc/g++ undefined reference to function () problem solving method

Source: Internet
Author: User

g++ compiles a program g++ Shm.c-o SHM,
With the Shm_open (), Shm_unlink () function, the following error has occurred in compiling:

`del_resource()‘`shm_unlink‘`main‘`shm_open‘collect2: error: ld returned 1 exit status

Later through the Shm_open () document, impressively found the following content:
Enter the man Shm_open carriage return in the terminal:

SYNOPSIS       #include <sys/mman.h>       #include <sys/stat.h>        /* For mode constants */       #include <fcntl.h>           /* For O_* constants */       int shm_open(constcharint oflag, mode_t mode);       int shm_unlink(constchar *name);       Link with -lrt.

Link WITH-LRT indicates that the compiler should add-LRT.
So the correct compile command should be:
g++ Shm.c-lrt-o SHM

I think similar to this compilation error, a good way is to look at the man document and find out if you need to show links to other libraries.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

gcc/g++ undefined reference to function () Problem resolution

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.