# Create a Library from IPO Objects

Libraries are often created using a library manager such as xiar for Linux/macOS or xilib for Windows. Given a list of objects, the library manager will insert the objects into a named library to be used in subsequent link steps.

## Linux and macOS

Use xiar to create a library from a list of objects. For example the following command creates a library named user.a containing the a.o and b.o objects:

    xiar cru user.a a.o b.o

If the objects have been created using [Q]ipo -c then the archive will not only contain a valid object, but the archive will also contain intermediate representation (IR) for that object file. For example, the following example will produce a.o and b.o that may be archived to produce a library containing both object code and IR for each source file. For example:

    icc -ipo -c a.cpp b.cpp

The commands generate mock object files, which when placed in archive will also be accompanied by a true object file.

Using xiar is the same as specifying `xild -lib`.

## macOS

When using xilibtool, specify -static to generate static libraries, or specify dynamic to create dynamic libraries. For example, the following command will create a static library named mylib.a that includes the a.o, b.o, and c.o objects:

    xilibtool -static -o mylib.a a.o b.o c.o

Alternately, the following example command will create a dynamic library named mylib.dylib that includes the a.o, b.o, and c.o objects.

    xilibtool -dynamic -o mylib.dylib a.o b.o c.o

Specifying xilibtool is the same as specifying `xild -libtool`.

## Windows

Use xilib or `xilink -lib` to create libraries of IPO mock object files and link them on the command line.

For example:

1. Assume that you create three mock object files using a command similar to:

       icl /c /Qipo a.cpp b.cpp c.cpp

2. Further assume a.obj contains the main subprogram. Create a library with a command similar to:

       xilib -out:main.lib b.obj c.obj

   or

       xilink -lib -out:main.lib b.obj c.obj

3. Link the library and the main program object file with a command similar to:

       xilink -out:result.exe a.obj main.lib

Parent topic: Interprocedural Optimization

## See Also

dynamiclib compiler option
ipo-c, Qipo-c , compiler option
static compiler option