Static link with libarchive on Windows with MinGW

I have been using libarchive in my project for some time now and it works fine, at the moment I am dynamically linking to it, so in Windows the libarchive.dll file must be present in the system. Now I would like to statically reference the library, so I don’t have to worry about the distribution of the DLL, but I am having real problems trying to achieve this!

In my make file, I have something like this: -Lpath / to // libarchive / -larchive

And it works, but it is a dynamic link. I do not know how to provide a static link.

I see two files in the libarchive directory: libarchive.dll.a and libarchive_static.a. I suppose I want to associate myself with libarchive_static.a, but I cannot say this, doing -larchive_static in the make file leads to linker errors.

I got the impression that the static libraries under the windows are lib files, but I don't get this type of file when creating libarchive.

How can I make a .lib file from libarchive. Also, as an additional question, what is the difference between a file and a lib file?

Update

To statically reference libarchive, your library command for make must contain:

-Lpath / to // libarchive / -larchive_static

This will be a link to the libarchive_static.a file. However, you also need to define LIBARCHIVE_STATIC in your code.

Now the problem is that libarchive depends on bzip2 libraries (as well as others), and if you do not have a static build, you will get linker errors, for example:

undefined link to `BZ2_bzCompressInit '

You need a static assembly of dependent libraries and a similar command for the linker after the libarchive command:

-Lpath / to / bzip2 / -lbzip2

You can either build bzip2 from the source, or do it in a simple way, and get the pre-built binary from the Gnu32Win project here: http://gnuwin32.sourceforge.net/packages.html

+7
source share
1 answer

Just add libarchive_static.a explicitly to your communication team.

 gcc -o YourApp.exe $(OBJS) path/to/libarchive_static.a $(OtherLibs) 

". lib" files differ from compiler to compiler (Borland, Microsoft, etc.), ".a" is the old "archive" format from the UNIX ar tool. It is now used only for combining static libraries.

I have something in my make file ... And it works, but it makes a dynamic link

The .a file actually contains some code to dynamically link to the .dll file, and not to libarchive itself. At startup, function pointers are highlighted and dynamic binding is performed.

+3
source

All Articles