Search code examples
autotoolsautoconfautomakelibtool

Libtool with library names that do not start with lib


I'm trying to convert a project to autotools using libtool. The target is a shared library that links against a third party library. The original Makefile approach used the following command line:

i686-w64-mingw32-g++ -g -shared -o libmycomponent.dll obj/mycomponent.o -L/path/to/thirdpary -lthirdpary -lwinpthread -lws2_32 -liphlpapi

This links fine.

However, when converting to autotools/libtool, I have within my Makefile.am I have:

libmycomponent_la_LIBADD += -L/path/to/thirdparty -lthirdparty

Now, the thirdparty library name does not start with lib. The name is just simply thirdparty.lib. When linking, I get a command line like:

/bin/bash ./libtool  --tag=CXX   --mode=link i686-w64-mingw32-g++ -std=gnu++11 -I./include -g -O2 -shared -no-undefined --enable-runtime-pseudo-reloc -version-info 1:0:0 -L/path/to/thirdparty  -o libmycomponent.la -rpath /usr/local/lib src/libmycomponent_la-mycomponent.lo -lthirdcomponent -lwinpthread -liphlpapi -lws2_32

This fails to link with:

*** Warning: linker path does not have real file for library -lthirdpary.
*** I have the capability to make that library automatically link in when
*** you link to this library.  But I can only do this if you have a
*** shared version of the library, which you do not appear to have
*** because I did check the linker path looking for a file starting
*** with libthirdpary but no candidates were found. (...for file magic test)
*** The inter-library dependencies that have been dropped here will be
*** automatically added whenever a program is linked with this library
*** or is declared to -dlopen it.

*** Since this library must not contain undefined symbols,
*** because either the platform does not support them or
*** it was explicitly requested with -no-undefined,
*** libtool will only create a static version of it.

However, if I copy thirdparty.lib to libthirdparty.lib, it links fine.

How can I get libtool to use the library name unchanged? I tried pulling in the file directly, e.g.:

libmycomponent_la_LIBADD += /path/to/thirdparty.lib

But I end up with undefined symbols (as if it didn't even try to pull in the file--which makes sense since it isn't a libtool file).

I also tried doing:

libmycomponent_la_LIBADD += -L/path/to/thirdparty -l:thirdparty

As recommended here, but the message changes to being unable to find lib:thirdparty.lib.


Solution

  • The solution is to sneak linker command line arguments past libtool. This is suggested here, and fully documented in the libtool FAQ. So, I tweaked my Makefile.am with:

    libmycomponent_la_LIBADD += -Wl,-L/path/to/thirdparty -Wl,-lthirdparty
    

    And now it happily links.