A summary of the undefined reference caused by incorrect GCC parameter-l transfer sequence

Source: Internet
Author: User

The command line used to compile a single file program of pthread is:

Gcc-O thread1-lpthread thread1.c

Error:

1 $ gcc -o thread1 -lpthread thread1.c2 /tmp/ccNqs6Bh.o: In function `main‘:3 thread1.c:(.text+0x49): undefined reference to `pthread_create‘4 thread1.c:(.text+0x5f): undefined reference to `pthread_join‘5 collect2: error: ld returned 1 exit status

After a careful look, the Code has been compiled and the link has an error, but the pthread library actually exists.

In addition, the GCC syntax is:
Usage: GCC [Options] file...

It's my favorite parameter passing method, and it's also passed in the prescribed way. Why? Do not play like this!

Take a closer look and find a '-V -- help' option, so gcc-V -- Help, [email protected] # $ % ^ &

The output result contains nearly 3000 rows !!!, Scare urine ~~~~~~~

No way. Google has the following instructions:
1. Link order of Libraries
2. c ++ shared library-undefined reference

Solution:
Put the reference to the library behind the source file, because it is a parameter passed to the linker!

To change it to this:
Gcc-O thread1 thread1.c-lpthread

 

Girl don't cry @ cnblogs.com/memset @ 2014.11.04

 

A summary of the undefined reference caused by incorrect GCC parameter-l transfer sequence

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.