Next: , Previous: Library Projects, Up: GNAT Project Manager


11.13 Using Third-Party Libraries through Projects

Whether you are exporting your own library to make it available to clients, or you are using a library provided by a third party, it is convenient to have project files that automatically set the correct command line switches for the compiler and linker.

Such project files are very similar to the library project files; See Library Projects. The only difference is that you set the Source_Dirs and Object_Dir attribute so that they point to the directories where, respectively, the sources and the read-only ALI files have been installed.

If you need to interface with a set of libraries, as opposed to a single one, you need to create one library project for each of the libraries. In addition, a top-level project that imports all these library projects should be provided, so that the user of your library has a single with clause to add to his own projects.

For instance, let's assume you are providing two static libraries liba.a and libb.a. The user needs to link with both of these libraries. Each of these is associated with its own set of header files. Let's assume furthermore that all the header files for the two libraries have been installed in the same directory headers. The ALI files are found in the same headers directory.

In this case, you should provide the following three projects:

     with "liba", "libb";
     project My_Library is
       for Source_Dirs use ("headers");
       for Object_Dir  use "headers";
     end My_Library;
     
     project Liba is
        for Source_Dirs use ();
        for Library_Dir use "lib";
        for Library_Name use "a";
        for Library_Kind use "static";
     end Liba;
     
     project Libb is
        for Source_Dirs use ();
        for Library_Dir use "lib";
        for Library_Name use "b";
        for Library_Kind use "static";
     end Libb;