rikyoz / bit7z

A C++ static library offering a clean and simple interface to the 7-zip shared libraries.
https://rikyoz.github.io/bit7z
Mozilla Public License 2.0
602 stars 110 forks source link

Do I need to build 7zip myself? #191

Closed TrueWodzu closed 4 months ago

TrueWodzu commented 4 months ago

Hi, thank you for the library!

It is my first day with it and I've read about compatibility issues with 7zip versions. I see that the library is downloading 7zip sources, but does not build them. Does it mean that I should build them on my own or am I missing something?

PS. I've noticed that for version 4.0.5 (tag) CMake states: "Target Version: 4.0.4"

rikyoz commented 4 months ago

Hi!

It is my first day with it and I've read about compatibility issues with 7zip versions. I see that the library is downloading 7zip sources, but does not build them. Does it mean that I should build them on my own or am I missing something?

I assume you're referring to the 7-Zip Version section of the README.

To be clear, on Windows, there should be no compatibility issues between different versions of the 7-Zip library and bit7z since the interfaces exposed by 7-Zip haven't changed in a long time. So, for example, if you're using the DLLs from 7-Zip v21.01 with a bit7z built with 7-Zip 23.01, you should have no problems. I have done many such tests and never had any problems. In general, however, I always recommend building bit7z for the same version of the DLLs you want to use in your program. This is more to be on the safe side and to avoid unforeseen compatibility problems.

The situation is different on Linux and MacOS, where 7-Zip 23.01 and later have introduced some breaking changes to the public API of the libraries. In this case, either specify the correct version using the BIT7Z_7ZIP_VERSION CMake option or, if you plan to use the shared libraries from 7-Zip 22.01 and earlier (or from p7zip), enable the BIT7Z_USE_LEGACY_IUNKNOWN build flag.

As for the need to build the libraries, it is not needed on Windows: you can use the 7z.dll that comes with 7-Zip (i.e., the one installed in C:\Program Files\7-Zip\/C:\Program Files (x86)\7-Zip\); if you only need to handle the 7z format, you can also download the 7za.dll from the 7-Zip website (the "extra" package).

Unfortunately, 7-Zip does not provide precompiled versions of the shared libraries for Linux and MacOS. I can provide the instructions for building them (which I'll eventually write down somewhere in the documentation anyway).

I hope to have explained it well, but if you have any further questions, feel free to ask.

PS. I've noticed that for version 4.0.5 (tag) CMake states: "Target Version: 4.0.4"

Thanks for pointing it out, I didn't notice it! I must have forgotten to update the version in the CMake project.

TrueWodzu commented 4 months ago

Hi @rikyoz thank you for the detailed answer. I am sorry, I wasn't very clear regarding the operating system. I wanted to use Linux, however the problem is that (as for my understanding) there are no official build scripts for 7-zip for Linux. I wanted to build shared library for version 23.01. Have you tried to build 7-Zip on Linux? Edit: Ah, I see that you know how to do this! :) It is no rush, it would be great to have the instructions some day, or even better to build 7-zip optionally during installation of bit7z. But I guess this will be a lot of work :)

TrueWodzu commented 4 months ago

BTW: I've found precompiled .so files for the newest version: https://packages.ubuntu.com/noble/7zip The problem is that it probably depends on other new packages that are not available on Ubuntu 22.04 which I am using currently.

rikyoz commented 4 months ago

Hey, sorry for the late reply!

I am sorry, I wasn't very clear regarding the operating system. I wanted to use Linux, however the problem is that (as for my understanding) there are no official build scripts for 7-zip for Linux. I wanted to build shared library for version 23.01.

I see. Building the 7-Zip library for Linux is actually fairly easy. In the source code of 7-Zip, you go to the directory CPP/7zip/Bundles/Format7zF/, and from there, you run the command make -j -f ../../cmpl_gcc.mak (if you want to use GCC) or make -j -f ../../cmpl_clang.mak (if you wish to use Clang). After the build finishes, you will find the 7z.so in a subdirectory of CPP/7zip/Bundles/Format7zF/.

For example:

> cd $7ZIP_SRC/CPP/7zip/Bundles/Format7zF/
> make -j -f ../../cmpl_gcc.mak
...
> ls -lh b/g/7z.so
-rwxrwxrwx 1 rikyoz rikyoz 2.7M Feb 28 08:47 b/g/7z.so

or even better to build 7-zip optionally during installation of bit7z. But I guess this will be a lot of work

In the mid-term, I plan to write some documentation in the Wiki on how to build the libraries on all the supported platforms. In the long term, I plan to make it easy to build the libraries, possibly within the same process of building bit7z.

TrueWodzu commented 4 months ago

Hey @rikyoz thank you very much, I would never figure out that the build script is there!

rikyoz commented 4 months ago

You're welcome! :)