Specify the libraries for the linker to use

  • strict warning: Non-static method Text_Wiki::singleton() should not be called statically in /var/www/drupal/6.x/sites/www.mingw.org/modules/pearwiki_filter/pearwiki_filter.module on line 475.
  • strict warning: Non-static method Text_Wiki::factory() should not be called statically in /usr/share/php/Text/Wiki.php on line 448.
  • strict warning: Non-static method Text_Wiki::isError() should not be called statically in /usr/share/php/Text/Wiki.php on line 449.
  • strict warning: Declaration of Text_Wiki_Parse_Emphasis::process() should be compatible with Text_Wiki_Parse::process(&$matches) in /usr/share/php/Text/Wiki/Parse/Mediawiki/Emphasis.php on line 0.

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.
  • Finally, please do not fall into the all-too-common trap of placing any "-l<name>" specification before the name of any source or object module which requires it. Where the source file bar.c has dependencies on the library archive libfoo.a, the command:
    $ gcc -lfoo bar.c

    is incorrect, and will surely lead to "undefined reference" errors. The correct form for this command is:

    $ gcc bar.c -lfoo

    Also, please do not be misled into the belief that this is a peculiarity of MinGW; it is a common requirement of the GNU linker, on all platforms which use it, and indeed of UNIX linkers in general, that libriaries must be specified after the names of all dependent modules. Please resist any temptation to report failure to support the former (incorrect) usage as a MinGW bug, for it is no such thing. If any other user attempts to convince you that the incorrect form works perfectly well on GNU/Linux (for example), then please politely refer them to the GCC Manual, and to the GNU Binutils Manual, point out that such usage is definitively incorrect, and advise them that they may have been getting away with such incorrect usage because some versions of the ELF platform linker, (of which GNU/Linux is an example), will forgive the error, specifically in the case of shared libraries; (such linkers will punish the error equally strenuously on every platform, in the case of statically linked libraries).

This wiki is not a forum for discussion of usage issues. Please use the mingw-users@lists.osdn.me list instead. We do not allow creation of comments by anonymous or untrusted users, on any page.
Site Status

Site maintenance performed successfully, site online Dec 13th 12:00 AM Eastern.