Creating and Linking to Library Projects

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Creating and Linking to Library Projects

22,322 Views
lpcware-support
Senior Contributor I

The LPCXpresso IDE provides project wizards for creating static library projects which can then be used by other projects within your workspace. In addition it also provides a simple mechanism for creating the links to a static library project from an application project.

Creating static library projects

Project wizards for creating C/C++ static library projects are provided via the standard project wizard accessible via

Quickstart Panel -> New project

Selecting the C/C++ Library project wizard for the chosen MCU family will then display one or more option screens.

After clicking on Finish, your library project will then be created with a source sub-directory with your chosen name (defaults to src), plus an optional inc sub-directory to store header files in. The top level of the project will also have a liblinks.xml placed in it (see below for how to use this).

Creating links to library projects

Using a library project requires the setting of a number of configuration options within the application project from which you wish to use the library project. Although it is possible to manually set things up, the LPCXpresso IDE also provides a more automated mechanism for creating the links to a static library project from an application project. This is done via the "smart update" wizard.

When a new static library project is created, a file called liblinks.xml will be created in the top level of the library project. If you right click on this file within the Project Explorer View, you can then select:

Smart update -> Smart update

148156_148156.jpglpcxpresso_liblinks_smartupdate.jpg

which will run the smart update wizard. This will pop up a dialog box listing all the projects in the current workspace. Simply tick those projects that you want to link to this particular static library project.

NOTE: Using the Smart update option with a liblinks.xml file assumes that both the library project and the application project you are linking it to have the two standard Debug and Release build configurations. If this is not the case, then you will need to set things up manually as described below.

Manually creating links to library projects

In order to use library projects, you will need to add appropriate include paths and libraries to your project. You will also need to do this for each build configuration (for example, Debug or Release). This is what using the Smart update option with a liblinks.xml file will do. But sometimes you may wish or need to do this manually (for instance if your library project does not have a liblinks.xml file).

First of all, ensure that the library project exists in the same workspace as your application project. Also ensure that the current build configuration for your project is Debug. Then...

  1. Open the Project properties. There are a number of ways of doing this. For example, make sure the Project is highlighted in the Project Explorer view then open the menu "Project -> Properties".

  2. In the left-hand list of the Properties window, open "C/C++ Build" and select "Settings" and then the "Tool Settings" tab.

  3. Now choose "MCU C Compiler - Directories" (or "MCU C Compiler - Includes", depending on tools version) and click on the "Add" icon.

  4. Now choose "Workspace" and then navigate to the directory within the library project containing any include files.

  5. Repeat step 4) if there is more than one include directories within the library project. For example if you are adding a link to the library LPC13_Lib, then what needs to appear on the include path is "${workspace_loc:/LPC13xx_Lib/inc}".

  6. If your project contains any assembler files, then choose "MCU Assembler - General" and add the include paths there too.

  7. Once you have added all the include paths, change to the other Build Configuration (Debug -> Release) in the drop down at the top of the properties window, and repeat steps 4), 5) and 6).

  8. Change the Build Configuration back to Debug.

  9. Choose "MCU Linker - Libraries" and click on the "Library search path (-L) Add" icon.

  10. Now choose "Workspace" and then navigate to the "Debug" directory within the library project. For example if you are adding a link to the library LPC13xx_Lib, then what needs to appear on the library search path is "${workspace_loc:/LPC13xx_Lib/Debug}".

  11. Now click on the "Libraries (-l) Add" icon. Type in the name of the library. This will be its project name, for example "LPC13xx_Lib". (You do not need to enter the quotes.)

  12. Now change to the other Build Configuration (Debug -> Release) in the drop down at the top of the properties window, and repeat steps 8), 9) and 10). Note that this time in step 8), you will need to navigate to the "Release" directory within the library project. Thus if you were adding a link to LPC13xx_Lib to your project, then what needs to appear on the library search path would be "${workspace_loc:/LPC13xx_Lib/Release}".

  13. Now you need to open "C/C++ General -> Paths and Symbols" in the left-hand list of the Properties window and open the "References" tab. Tick the appropriate box(es) for the library project(s) that your project uses.

  14. Finally you need to add a project reference from your application project to the library project. To do this, select "Project References" in the left-hand list of the Properties window, and tick the appropriate box(es).

Note that if your application project makes use of several library projects, you will need to repeat the above sequence for each library project.

A Note on library naming

The GNU tools require libraries to be named liblibrary_name.a. However, when you link with a library, you only use the library_name. For example, if you have a library called libmylib.a, you would link with mylib.

Tags (2)
1 Reply

2,924 Views
Slaymaker
Contributor III

That liblinks.xml file is a lot closer, thanks. Issues:

1) Eclipse has the wrong values in that file (so I have to fix them manually)

2) I have to go into the library project and use that inscrutable menu item to manually "push" the settings to all dependent projects.

3) The injected values use the ${workspace_loc:...} macro, which assumes Windows directory separators, unlike the generated Makefile, which interferes with WSL builds (which I'm using--I have Eclipse CDT run wsl make ...).

The other IDEs and build systems I've used do this in the when adding a library project to a dependent project--so it's neither manual nor using a menu completely unrelated to the process of adding a library dependency...

Can MCUxpresso just look for and act on liblinks.xml in a library project when I go into a new project and add a dependency to that library project?

- Barrie

0 Kudos
Reply