I have problems with linking to a library called xyz.a
in my Eclipse CDT MinGW project. Eclipse projects cannot find this library unless I rename it to libxyz.a
.
I have added:
Properties/C C++ General/Paths and Symbols/Library Paths
. Properties/C C++ General/Paths and Symbols/Libraries
. Library name I specified here is xyz
, so it's without extesion. What should I specify here in order to successfully include xyz.a
without having to rename it to libxyz.a
? Some info I found online:
How do I specify the libraries to be searched by the linker?
MinGW supports libraries named according to the "<name>.lib" and "<name>.dll" conventions, in addition to the normal "lib<name>.a" convention common on *nix systems. To include libraries named according to any of these conventions, simply add an associated "-l<name>" specification to the compiler command, ensuring it is placed after the name of the module in which the reference appears.
Note that, if the library is not found in any of the default library search paths, you may also need to insert an appropriate "-L<dir>" switch to specify its location; (it is recommended that you place the "-L<dir>" switch before the "-l<name>" specification which requires it).
Also note that the library names "lib<name>.a" and "lib<name>.lib" are not equivalent; if you have a library named according to the aberrant "lib<name>.lib" convention, it will not be found by an "-l<name>" specification -- if you cannot rename the library, you must use the form "-llib<name>" instead.
You can link a library called oddname
- where oddname
includes any file-extension - in Eclipse CDT like this:
Navigate in the project Properties -> C/C++ Build -> Settings -> Tool Settings -> GCC C++ Linker -> Libraries.
In Libraries(-l) panel add :oddname
If necessary, in the Library search path(-L) panel add the path to
oddname
OK out
This setting will add the option -l:oddname
to the generated GCC link
command. -l:filename
is the form of the -l
option signifying that
the conventional lib
prefix and the {.so|.a}
extension are not implied and that
filename
is the actual filename of the library to be linked. Here is the documentation