How do I link a library file in GCC that does not start with lib?

JeffV picture JeffV · Apr 19, 2012 · Viewed 12.9k times · Source

When I link a library such as libm in with ld, I need to drop the lib prefix. What if the file does not follow this naming convention? Is there a way to link it other than renaming the file?

Answer

Shawn picture Shawn · Sep 18, 2014

You can have the linker search for a library named without the lib prefix:

gcc main.o -L/path/to/foo -l:foo.a

This is especially useful in environments where a list of libraries is specified and the -l flag is prepended later (eg some makefiles or eclipse CDT)