How to use Custom Library Names with GNU Linker and Eclipse

By default, the GNU Linker expects a very special naming scheme for the libraries: the library name has to be surrounded by “lib” and the “.a” extension:

lib<NAME>.a

But what if the library I want to use does not conform to that naming standard?

Non-conforming Library Naming

Non-conforming Library Naming

As outlined in Creating and using Libraries with ARM gcc and Eclipse the library name has to be something like

libMyLibraryName.a

with the ‘lib’ prefix and the ‘.a’ as extension.

What is a common confusion point: for the linker I have to specify the library using the -l option without (!!!) the prefix and extension:

-lMyLibraryName

Using Eclipse (e.g. NXP MCUXpresso IDE), I have a dialog where I can put in the library name (-l option) and where the library is located (-L option):

Libraries for Linker (MCUXpresso IDE)

Libraries for Linker (MCUXpresso IDE)

So how to use a library with a non-standard naming? Obviously I can rename the library (this is actually what I did in the past). But there is yet another way: use the ‘:’ (colon) in the linker -l option. If using the ‘:’ I can specify the real library name with

-l:MyRealLibraryName

For example if my library is named

mathFunctions.lib

I can use

-l:mathFunctions.lib

The same thing works in the Eclipse dialog:

Colon in linker option to link non-standard library name

Colon in linker option to link non-standard library name

That’s it! 🙂

Happy GNU Linking 🙂

Links

3 thoughts on “How to use Custom Library Names with GNU Linker and Eclipse

  1. Pingback: Tutorial: Porting BLE+NRF Kinetis Design Studio Project to MCUXpresso IDE | MCU on Eclipse

  2. Pingback: Managing Project and Library Dependencies with Eclipse CDT | MCU on Eclipse

What do you think?

This site uses Akismet to reduce spam. Learn how your comment data is processed.