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
623 stars 113 forks source link

[Feature Request]: Have the devs considered porting this over to Linux #53

Closed Yasand123 closed 11 months ago

Yasand123 commented 2 years ago

Feature description

I really like this lib, unfortunately it's Windows exclusive. Are there plans to port this over to Linux (considering 7z now supports Linux officially?). If not, do you know of some viable alternatives (besides libarchive), or whether it's possible to use this lib somehow on a Linux machine?

Additional context

No response

Code of Conduct

rikyoz commented 2 years ago

Hi! First of all, thank you for appreciating the library! The next major version, v4.0, will introduce support to both Linux and macOS, as well as many other new functionalities and changes. The minimum requirements will be to use at least GCC v4.9 or Clang v3.5. It will support using the shared libraries from either 7-zip or p7zip (I successfully tested it with the 7z.so libraries from both projects). I've pretty much finished the works on the next version; the API should be stable (unless unforeseen issues). If you want to try it, please check the pre-release/v4.0.0-beta branch. At the moment, I'm working on some minor details and on updating the documentation; then, I'll release a first beta version, hopefully soon. If you decide to give it a try, please let me know of any issues (or if it works fine)!

otrejo-soria commented 2 years ago

It seems that the linux platform is not building. I get the follwoing errors

[ 98%] Building CXX object CMakeFiles/bit7z64.dir/src/internal/windows.cpp.o
/home/user/github/bit7z/src/internal/windows.cpp: In function ‘bit7z::OLECHAR* AllocStringBuffer(LPCSTR, uint64_t)’:
/home/user/github/bit7z/src/internal/windows.cpp:93:14: error: ‘memcpy’ is not a member of ‘std’
   93 |         std::memcpy( result, str, byte_length );
      |              ^~~~~~
/home/user/github/bit7z/src/internal/util.cpp: In function ‘std::string bit7z::narrow(const wchar_t*)’:
/home/user/github/bit7z/src/internal/util.cpp:38:10: error: ‘wstring_convert’ is not a member of ‘std’
   38 |     std::wstring_convert<convert_type, wchar_t> converter;
      |          ^~~~~~~~~~~~~~~
/home/user/github/bit7z/src/internal/util.cpp:38:38: error: expected primary-expression before ‘,’ token
   38 |     std::wstring_convert<convert_type, wchar_t> converter;
      |                                      ^
/home/user/github/bit7z/src/internal/util.cpp:38:40: error: expected primary-expression before ‘wchar_t’
   38 |     std::wstring_convert<convert_type, wchar_t> converter;
      |                                        ^~~~~~~
/home/user/github/bit7z/src/internal/util.cpp:39:12: error: ‘converter’ was not declared in this scope
   39 |     return converter.to_bytes( wideString );
      |            ^~~~~~~~~
/home/user/github/bit7z/src/internal/util.cpp: In function ‘std::wstring bit7z::widen(const string&)’:
/home/user/github/bit7z/src/internal/util.cpp:43:10: error: ‘wstring_convert’ is not a member of ‘std’
   43 |     std::wstring_convert<convert_type, wchar_t> converter;
      |          ^~~~~~~~~~~~~~~
/home/user/github/bit7z/src/internal/util.cpp:43:38: error: expected primary-expression before ‘,’ token
   43 |     std::wstring_convert<convert_type, wchar_t> converter;
      |                                      ^
/home/user/github/bit7z/src/internal/util.cpp:43:40: error: expected primary-expression before ‘wchar_t’
   43 |     std::wstring_convert<convert_type, wchar_t> converter;
      |                                        ^~~~~~~
/home/user/github/bit7z/src/internal/util.cpp:44:12: error: ‘converter’ was not declared in this scope
   44 |     return converter.from_bytes( narrowString );
      |            ^~~~~~~~~
make[2]: *** [CMakeFiles/bit7z64.dir/build.make:700: CMakeFiles/bit7z64.dir/src/internal/windows.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[2]: *** [CMakeFiles/bit7z64.dir/build.make:687: CMakeFiles/bit7z64.dir/src/internal/util.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/bit7z64.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

The fix seems pretty simple. The following headers and need to be added.

diff --git a/src/internal/util.cpp b/src/internal/util.cpp
index afd2158..8403724 100644
--- a/src/internal/util.cpp
+++ b/src/internal/util.cpp
@@ -22,6 +22,7 @@
 #ifndef _WIN32
 #include "internal/util.hpp"
 #include <codecvt>
+#include <locale>
 #include <sstream>
​
 using std::wostringstream;
diff --git a/src/internal/windows.cpp b/src/internal/windows.cpp
index e6bde2b..178d65f 100644
--- a/src/internal/windows.cpp
+++ b/src/internal/windows.cpp
@@ -25,6 +25,7 @@
 #include "internal/windows.hpp"
​
 #include <iostream>
+#include <cstring>
​
​
 size_t wcsnlen_s( const wchar_t* str, size_t max_size ) 

I tested this with clang 10 and gcc 9.4

rikyoz commented 2 years ago

It seems that the linux platform is not building. I get the follwoing errors

This is actually quite strange! I just tested again to be sure, and it compiles fine with Clang 10/12 and GCC 9.3 (at least on Ubuntu WSL)!

The fix seems pretty simple. The following headers and need to be added.

Yeah, I will apply the patch you suggested. Thank you for pointing it out!

otrejo-soria commented 2 years ago

I agree. Another programmer that I am working with hit an extra compiler error that I didn't hit

/home/user/bit7z/src/internal/windows.cpp: In function 'bit7z::OLECHAR* AllocStringBuffer(LPCSTR, uint64_t)':
/home/user/bit7z/src/internal/windows.cpp:65:44: error: 'numeric_limits' is not a member of 'std'
   65 |     constexpr auto max_prefix_value = std::numeric_limits< bstr_prefix_t >::max();
      |          

He ended up adding <limits> header as well. Both of us were using Ubuntu 20. Not sure if it has to do with the standard libraries we have in these VMs.

rikyoz commented 2 years ago

Not sure if it has to do with the standard libraries we have in these VMs.

It's the only reason that comes to my mind. It's really strange.

Anyway, thank you again! I'll include that other header as well.

rikyoz commented 11 months ago

Implemented in v4.0.0.

Yasand123 commented 11 months ago

Thank you so much!