Linux Makefile Tutorial Update function library file 10 [go]

Source: Internet
Author: User

Updating a function library file with make

———————————

A library file is a packaged file for an object file (a program-compiled intermediate file). Under UNIX, it is generally the command "AR" to complete the packaging work.

Member of a library file

A function library file consists of multiple files. You can specify the function library file and its composition in the following format:

Archive (Member)

This is not a command, but a definition of a target and a dependency. In general, this usage is basically for the "ar" command to serve. Such as:

Foolib (HACK.O): HACK.O

AR cr foolib HACK.O

If you want to specify more than one member, separate them with spaces, such as:

Foolib (HACK.O kludge.o)

It is equivalent to:

Foolib (HACK.O) foolib (KLUDGE.O)

You can also use the shell's file wildcard characters to define, such as:

Foolib (*.O)

Second, the hidden rules of function library members

When make searches for an implicit rule for a target, a special feature is that if the target is in the form of "A (m)", it will turn the target into "(m)". So, if our members are "%.O" pattern definitions, and if we call makefile in the form of "make FOO.A (BAR.O)", the implied rules go to the "bar.o" rule, and if there is no rule to define BAR.O, then the built-in implication rules take effect, Make will go to the bar.c file to generate the BAR.O, and if you can find it, the command you want to execute is roughly the following:

Cc-c Bar.c-o BAR.O

AR R foo.a bar.o

Rm-f BAR.O

Another variable to note is "$%", which is an automation variable for a proprietary library file, see the "Automation variables" section for instructions.

Third, the suffix rule of the function library file

You can use "suffix rules" and "implied rules" to generate a library package file, such as:

. C.A:

$ (CC) $ (CFLAGS) $ (cppflags)-C $<-O $*.O

$ (AR) R [email protected] $*.o

$ (RM) $*.O

It is equivalent to:

(%.O):%.c

$ (CC) $ (CFLAGS) $ (cppflags)-C $<-O $*.O

$ (AR) R [email protected] $*.o

$ (RM) $*.O

Iv. Matters of note

Be careful with the parallel mechanism of make (the "-j" parameter) when making a library package file generation. If more than one AR command runs on the same library package at the same time, it can corrupt the library file. Therefore, in the make future release, a mechanism should be provided to avoid parallel operations occurring on the function packaging file.

But for now, you should not try to avoid using the "-j" parameter.

Related Article

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.