Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't Libtool want to link with a static library?

I want to build a shared library that uses ZipArchive using GNU Autotools but I'm having this problem:

Warning: linker path does not have real file for library -lziparch.
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 libziparch and none of the candidates passed a file format test
using a file magic. Last file checked: /usr/local/ZipArchive/ZipArchive/libziparch.a
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.

If I build a static library or if I use a shared library of ZipArchive it works but the problem is that the makefile that comes with ZipArchive source code only builds a static library.

How can I force Libtool to link with a static library?

like image 484
Gabi Avatar asked Jun 26 '12 10:06

Gabi


People also ask

What happens when you link a static library?

Static Linking and Static Libraries is the result of the linker making copy of all used library functions to the executable file. Static Linking creates larger binary files, and need more space on disk and main memory.

How do I link a static library?

You should #include "libstatic. h" , i.e. use the appropriate header file in your code (that's why your code doesn't compile) and include the path to your libstatic. a in the linker options as one of your input libraries. This webpage has some examples on linking to a static library, e.g.

Can a static library use a dynamic library?

Yes for instance when you call windows functions from within your static lib they are normally from some dynamic library so there should be no difference.


1 Answers

Generally, static archives are created with non-pic object files and they cannot be put into shared libraries.

What this message is telling you though, is that when a program links to YOUR library using Libtool, that -lziparch will get added to the link. So you don't need to change anything unless you're building a module for an interpreted language. In that case, you will have to build ZipArchive as a shared library. In addition, this wouldn't work on a platform like MS Windows where shared libraries (DLLs) have to resolve all their symbols at link time.

All that said, if your ziparch static lib is PIC code, you can use the -whole-archive flag when linking it to your library. This would be the least portable solution though.

like image 179
Robert Boehne Avatar answered Oct 07 '22 01:10

Robert Boehne