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

Advertisements

One thought on “How to use Custom Library Names with GNU Linker and Eclipse

What do you think?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s