From 2578e6e77f766a8c61299962ebc15cae780081d8 Mon Sep 17 00:00:00 2001 From: "Azamat H. Hackimov" Date: Wed, 22 Jul 2026 11:02:34 +0300 Subject: [PATCH 01/12] Update cmake project Set cmake_minimum_required to 3.24 as current CMake-4 not supporting <3.5. Use new features that provides 3.24: CMAKE_COMPILE_WARNING_AS_ERROR, CMAKE_POSITION_INDEPENDENT_CODE, and others. Enforce C++14 standard. Add various configuration options for convenience: * LIB7ZIP_ENABLE_TESTING - enables building testing programs * LIB7ZIP_WARNING_AS_ERROR - enforce CMAKE_COMPILE_WARNING_AS_ERROR Formatting code and cleanup. --- CMakeLists.txt | 73 ++++++++++++++++----------------------------- README.md | 2 +- src/CMakeLists.txt | 70 +++++++++++++++++++++++++++---------------- test/CMakeLists.txt | 41 ++++++++++++++----------- 4 files changed, 96 insertions(+), 90 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 89a2934..9506f77 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,70 +1,49 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.8) +CMAKE_MINIMUM_REQUIRED(VERSION 3.24) -CMAKE_POLICY( - SET CMP0048 NEW +PROJECT(lib7zip + VERSION 4.0.0 + LANGUAGES CXX ) -PROJECT (lib7zip - VERSION 4.0.0 -) - -INCLUDE(ExternalProject) +SET(CMAKE_CXX_STANDARD 14) +SET(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_POSITION_INDEPENDENT_CODE ON) -IF(APPLE) +IF (APPLE) SET(CMAKE_MACOSX_RPATH 1) SET(CMAKE_PREFIX_PATH /usr/local) -ENDIF() +ENDIF () -IF(NOT CMAKE_BUILD_TYPE) +IF (NOT CMAKE_BUILD_TYPE) SET(CMAKE_BUILD_TYPE "DEBUG") #SET(CMAKE_BUILD_TYPE "RELEASE") #SET(CMAKE_BUILD_TYPE "RELWITHDEBINFO") #SET(CMAKE_BUILD_TYPE "MINSIZEREL") -ENDIF() - -SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/") +ENDIF () -OPTION(BUILD_SHARED_LIB "build shared library" OFF) - -# Use submodule 7zip source by default, allow override with SEVENZIP_SOURCE_DIR -IF(NOT DEFINED SEVENZIP_SOURCE_DIR) - SET(SEVENZIP_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/7zip") -ENDIF() +SET(SEVENZIP_SOURCE_DIR "${PROJECT_SOURCE_DIR}/third_party/7zip" CACHE STRING "Location of 7zip sources") +OPTION(LIB7ZIP_BUILD_SHARED_LIB "Build shared library" OFF) +OPTION(LIB7ZIP_ENABLE_TESTING "Enable testing" ${PROJECT_IS_TOP_LEVEL}) +OPTION(LIB7ZIP_WARNING_AS_ERROR "Threat all compiler warnings as errors" ${PROJECT_IS_TOP_LEVEL}) IF (NOT IS_DIRECTORY ${SEVENZIP_SOURCE_DIR}) MESSAGE(FATAL_ERROR "7zip source not found at ${SEVENZIP_SOURCE_DIR}. Please ensure git submodule is initialized: git submodule update --init --recursive") -ENDIF() +ENDIF () + +IF (LIB7ZIP_WARNING_AS_ERROR) + SET(CMAKE_COMPILE_WARNING_AS_ERROR ON) +ENDIF () -SET(SEVENZIP_INCLUDE_PATH "${SEVENZIP_SOURCE_DIR}" +SET(SEVENZIP_INCLUDE_PATH + "${SEVENZIP_SOURCE_DIR}" "${SEVENZIP_SOURCE_DIR}/CPP" "${SEVENZIP_SOURCE_DIR}/CPP/Common" "${SEVENZIP_SOURCE_DIR}/CPP/Windows" "${SEVENZIP_SOURCE_DIR}/C" - "${CMAKE_CURRENT_SOURCE_DIR}/includes" + "${PROJECT_SOURCE_DIR}/src" ) - -if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") - set(warnings -Wall -Wextra -Werror -Wno-unused-parameter) - set(cxx_warnings -Wno-class-memaccess) - set(no_undefined -Wl,--no-undefined) -elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - set(warnings -Wall -Wextra -Werror -Wno-inconsistent-missing-override -Wno-unused-parameter) - set(cxx_warnings "") - set(no_undefined -Wl,-undefined,error) -elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") - set(warnings /W4 /WX /EHsc) - set(no_undefined "") - set(cxx_warnings "") -endif() - -SET(CXX_STANDARD_REQUIRED OFF) -SET(CXX_EXTENSION NO) - -if (NOT CONFIGURED_ONCE) -ADD_COMPILE_OPTIONS(-fPIC -std=c++14 ${warnings} ${cxx_warnings}) -ADD_LINK_OPTIONS(${no_undefined}) -endif() - ADD_SUBDIRECTORY(src) -ADD_SUBDIRECTORY(test) +IF (LIB7ZIP_ENABLE_TESTING) + ADD_SUBDIRECTORY(test) +ENDIF () diff --git a/README.md b/README.md index 6d50610..7c10894 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ ar rcs lib7zip.a *.o - **7-Zip 25.0 Source**: Included as git submodule at `third_party/7zip/` - **C++ Compiler**: GCC 8+ or Clang 10+ with C++14 support -- **Build Tools**: CMake 3.5+ for CMake method, git for submodule management +- **Build Tools**: CMake 3.24+ for CMake method, git for submodule management - **System Libraries**: pthread, dl (standard on most Linux systems) ## 🔧 Build Instructions diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index dc96fc8..d7b6bb4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,41 +1,61 @@ SET(lib7zip_src -7ZipArchive.cpp 7ZipCompressCodecsInfo.cpp 7ZipFunctions.h OSFunctions_UnixLike.cpp -7ZipArchiveItem.cpp 7ZipCompressCodecsInfo.h 7ZipInStreamWrapper.cpp HelperFuncs.cpp OSFunctions_UnixLike.h -7ZipArchiveOpenCallback.cpp 7ZipDllHandler.cpp 7ZipInStreamWrapper.h HelperFuncs.h OSFunctions_Win32.cpp -7ZipArchiveOpenCallback.h 7ZipDllHandler.h 7ZipObjectPtrArray.cpp OSFunctions.h OSFunctions_Win32.h -7ZipCodecInfo.cpp 7ZipFormatInfo.cpp 7ZipOpenArchive.cpp OSFunctions_OS2.cpp lib7zip.h -7ZipCodecInfo.h 7ZipFormatInfo.h 7zipLibrary.cpp OSFunctions_OS2.h compat.h + 7ZipArchive.cpp + 7ZipArchiveItem.cpp + 7ZipArchiveOpenCallback.cpp + 7ZipArchiveOpenCallback.h + 7ZipCodecInfo.cpp + 7ZipCodecInfo.h + 7ZipCompressCodecsInfo.cpp + 7ZipCompressCodecsInfo.h + 7ZipDllHandler.cpp + 7ZipDllHandler.h + 7ZipFormatInfo.cpp + 7ZipFormatInfo.h + 7ZipFunctions.h + 7ZipInStreamWrapper.cpp + 7ZipInStreamWrapper.h + 7ZipObjectPtrArray.cpp + 7ZipOpenArchive.cpp + 7zipLibrary.cpp + HelperFuncs.cpp + HelperFuncs.h + OSFunctions.h + OSFunctions_OS2.cpp + OSFunctions_OS2.h + OSFunctions_UnixLike.cpp + OSFunctions_UnixLike.h + OSFunctions_Win32.cpp + OSFunctions_Win32.h + compat.h + lib7zip.h ) -SET(lib7zip_NODIST_SOURCES ${SEVENZIP_SOURCE_DIR}/CPP/Common/MyWindows.cpp - ${SEVENZIP_SOURCE_DIR}/CPP/Windows/PropVariant.cpp +SET(lib7zip_NODIST_SOURCES + ${SEVENZIP_SOURCE_DIR}/CPP/Common/MyWindows.cpp + ${SEVENZIP_SOURCE_DIR}/CPP/Windows/PropVariant.cpp ) ADD_LIBRARY(lib7zip STATIC ${lib7zip_src} - ${lib7zip_NODIST_SOURCES} - ) + ${lib7zip_NODIST_SOURCES} +) SET_TARGET_PROPERTIES(lib7zip PROPERTIES - OUTPUT_NAME "7zip" + OUTPUT_NAME "7zip" ) -SET_TARGET_PROPERTIES(lib7zip PROPERTIES LINKER_LANGUAGE CXX) - TARGET_INCLUDE_DIRECTORIES(lib7zip PRIVATE "${SEVENZIP_INCLUDE_PATH}" ) -IF (BUILD_SHARED_LIB) -ADD_LIBRARY(lib7zip_shared SHARED ${lib7zip_src} - ${lib7zip_NODIST_SOURCES} -) -SET_TARGET_PROPERTIES(lib7zip_shared PROPERTIES +IF (LIB7ZIP_BUILD_SHARED_LIB) + ADD_LIBRARY(lib7zip_shared SHARED ${lib7zip_src} + ${lib7zip_NODIST_SOURCES} + ) + SET_TARGET_PROPERTIES(lib7zip_shared PROPERTIES OUTPUT_NAME "7zip" -) - -SET_TARGET_PROPERTIES(lib7zip_shared PROPERTIES LINKER_LANGUAGE CXX) + ) -TARGET_INCLUDE_DIRECTORIES(lib7zip_shared PRIVATE - "${SEVENZIP_INCLUDE_PATH}" -) -ENDIF() + TARGET_INCLUDE_DIRECTORIES(lib7zip_shared PRIVATE + "${SEVENZIP_INCLUDE_PATH}" + ) +ENDIF () diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 07d33e7..7f8bd58 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,30 +1,37 @@ SET(common_src - stdafx.cpp stdafx.h + stdafx.cpp + stdafx.h ) -SET (test_src Test7Zip.cpp Test7ZipCryptFileName.cpp Test7ZipMulti.cpp Test7ZipSignature.cpp -Test7Zip2.cpp Test7ZipDmg.cpp Test7ZipRar5.cpp test_archive.cpp +SET(test_src + Test7Zip.cpp + Test7ZipCryptFileName.cpp + Test7ZipMulti.cpp + Test7ZipSignature.cpp + Test7Zip2.cpp + Test7ZipDmg.cpp + Test7ZipRar5.cpp + test_archive.cpp ) -FOREACH(f ${test_src}) +FOREACH (f ${test_src}) -GET_FILENAME_COMPONENT(test_target_name ${f} NAME_WE) + GET_FILENAME_COMPONENT(test_target_name ${f} NAME_WE) -MESSAGE("generate target ${test_target_name} for ${f}") + MESSAGE(STATUS "generate target ${test_target_name} for ${f}") -ADD_EXECUTABLE(${test_target_name} + ADD_EXECUTABLE(${test_target_name} ${common_src} ${f} -) + ) -TARGET_INCLUDE_DIRECTORIES(${test_target_name} PRIVATE - "../src" - "${SEVENZIP_INCLUDE_PATH}" -) + TARGET_INCLUDE_DIRECTORIES(${test_target_name} PRIVATE + "${SEVENZIP_INCLUDE_PATH}" + ) -TARGET_LINK_LIBRARIES(${test_target_name} - lib7zip - ${CMAKE_DL_LIBS} -) + TARGET_LINK_LIBRARIES(${test_target_name} + lib7zip + ${CMAKE_DL_LIBS} + ) -ENDFOREACH() +ENDFOREACH () From 1af9cd424295916f9497241e90aa334f9392c37d Mon Sep 17 00:00:00 2001 From: "Azamat H. Hackimov" Date: Wed, 22 Jul 2026 11:07:07 +0300 Subject: [PATCH 02/12] Fix building with GCC-16 CPP/7zip/Common/FileStreams.h requires additional code from 7zip. Otherwise, compilation will fail with "undefined reference to `vtable for COutFileStream'" and "undefined reference to `NC::NFile::NIO::CFileBase::Close()'" errors. --- src/7ZipArchive.cpp | 1 - src/7ZipArchiveItem.cpp | 1 - src/HelperFuncs.cpp | 1 - 3 files changed, 3 deletions(-) diff --git a/src/7ZipArchive.cpp b/src/7ZipArchive.cpp index 22c3b83..b9ab561 100644 --- a/src/7ZipArchive.cpp +++ b/src/7ZipArchive.cpp @@ -15,7 +15,6 @@ #include "CPP/Common/MyCom.h" #include "CPP/7zip/ICoder.h" #include "CPP/7zip/IPassword.h" -#include "CPP/7zip/Common/FileStreams.h" #include "HelperFuncs.h" diff --git a/src/7ZipArchiveItem.cpp b/src/7ZipArchiveItem.cpp index 3d47b6c..65dc9ae 100644 --- a/src/7ZipArchiveItem.cpp +++ b/src/7ZipArchiveItem.cpp @@ -9,7 +9,6 @@ #include "CPP/Common/MyCom.h" #include "CPP/7zip/ICoder.h" #include "CPP/7zip/IPassword.h" -#include "CPP/7zip/Common/FileStreams.h" #include "lib7zip.h" #include "HelperFuncs.h" diff --git a/src/HelperFuncs.cpp b/src/HelperFuncs.cpp index 53d6bd6..b39aa62 100644 --- a/src/HelperFuncs.cpp +++ b/src/HelperFuncs.cpp @@ -19,7 +19,6 @@ #include "CPP/Common/MyCom.h" #include "CPP/7zip/ICoder.h" #include "CPP/7zip/IPassword.h" -#include "CPP/7zip/Common/FileStreams.h" #include From 3fbfa95bc1178f8c0c08d4c86d4f88653596df24 Mon Sep 17 00:00:00 2001 From: "Azamat H. Hackimov" Date: Wed, 22 Jul 2026 11:10:06 +0300 Subject: [PATCH 03/12] Fix building with CLang Fix -Winconsistent-missing-override compilation failure. --- src/7ZipArchive.cpp | 20 ++++++++++---------- src/7ZipArchiveOpenCallback.h | 12 ++++++------ src/7ZipCompressCodecsInfo.h | 10 +++++----- src/7ZipInStreamWrapper.h | 6 +++--- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/7ZipArchive.cpp b/src/7ZipArchive.cpp index b9ab561..782c853 100644 --- a/src/7ZipArchive.cpp +++ b/src/7ZipArchive.cpp @@ -34,21 +34,21 @@ class C7ZipOutStreamWrap: public: Z7_COM_UNKNOWN_IMP_1(IOutStream) - STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) throw() + STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) throw() override { return m_pOutStream->Seek(offset, seekOrigin, newPosition); } #if MY_VER_MAJOR > 9 || (MY_VER_MAJOR == 9 && MY_VER_MINOR>=20) - STDMETHOD(SetSize)(UInt64 newSize) throw() + STDMETHOD(SetSize)(UInt64 newSize) throw() override #else - STDMETHOD(SetSize)(Int64 newSize) throw() + STDMETHOD(SetSize)(Int64 newSize) throw() override #endif { return m_pOutStream->SetSize(newSize); } - STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize) throw() + STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize) throw() override { return m_pOutStream->Write(data, size, processedSize); } @@ -67,16 +67,16 @@ class CArchiveExtractCallback: Z7_COM_UNKNOWN_IMP_1(ICryptoGetTextPassword) // IProgress - STDMETHOD(SetTotal)(UInt64 size) throw(); - STDMETHOD(SetCompleted)(const UInt64 *completeValue) throw(); + STDMETHOD(SetTotal)(UInt64 size) throw() override; + STDMETHOD(SetCompleted)(const UInt64 *completeValue) throw() override; // IArchiveExtractCallback - STDMETHOD(GetStream)(UInt32 index, ISequentialOutStream **outStream, Int32 askExtractMode) throw(); - STDMETHOD(PrepareOperation)(Int32 askExtractMode) throw(); - STDMETHOD(SetOperationResult)(Int32 resultEOperationResult) throw(); + STDMETHOD(GetStream)(UInt32 index, ISequentialOutStream **outStream, Int32 askExtractMode) throw() override; + STDMETHOD(PrepareOperation)(Int32 askExtractMode) throw() override; + STDMETHOD(SetOperationResult)(Int32 resultEOperationResult) throw() override; // ICryptoGetTextPassword - STDMETHOD(CryptoGetTextPassword)(BSTR *aPassword) throw(); + STDMETHOD(CryptoGetTextPassword)(BSTR *aPassword) throw() override; virtual bool SetFileSymLinkAttrib() { return false; diff --git a/src/7ZipArchiveOpenCallback.h b/src/7ZipArchiveOpenCallback.h index 760bd0a..8f2fe84 100644 --- a/src/7ZipArchiveOpenCallback.h +++ b/src/7ZipArchiveOpenCallback.h @@ -19,17 +19,17 @@ public IArchiveOpenCallback, ); // IArchiveOpenCallback - STDMETHOD(SetTotal)(const UInt64 *files, const UInt64 *bytes) throw(); - STDMETHOD(SetCompleted)(const UInt64 *files, const UInt64 *bytes) throw(); + STDMETHOD(SetTotal)(const UInt64 *files, const UInt64 *bytes) throw() override; + STDMETHOD(SetCompleted)(const UInt64 *files, const UInt64 *bytes) throw() override; // IArchiveOpenVolumeCallback - STDMETHOD(GetProperty)(PROPID propID, PROPVARIANT *value) throw(); - STDMETHOD(GetStream)(const wchar_t *name, IInStream **inStream) throw(); + STDMETHOD(GetProperty)(PROPID propID, PROPVARIANT *value) throw() override; + STDMETHOD(GetStream)(const wchar_t *name, IInStream **inStream) throw() override; // ICryptoGetTextPassword - STDMETHOD(CryptoGetTextPassword)(BSTR *password) throw(); + STDMETHOD(CryptoGetTextPassword)(BSTR *password) throw() override; - STDMETHOD(SetSubArchiveName(const wchar_t *name)) throw() { + STDMETHOD(SetSubArchiveName(const wchar_t *name)) throw() override { _subArchiveMode = true; _subArchiveName = name; TotalSize = 0; diff --git a/src/7ZipCompressCodecsInfo.h b/src/7ZipCompressCodecsInfo.h index f5a7204..cf9b871 100644 --- a/src/7ZipCompressCodecsInfo.h +++ b/src/7ZipCompressCodecsInfo.h @@ -12,13 +12,13 @@ class C7ZipCompressCodecsInfo : public ICompressCodecsInfo, Z7_COM_UNKNOWN_IMP_1(ICompressCodecsInfo) #if MY_VER_MAJOR >= 15 - STDMETHOD(GetNumMethods)(UInt32 *numMethods) throw(); + STDMETHOD(GetNumMethods)(UInt32 *numMethods) throw() override; #else - STDMETHOD(GetNumberOfMethods)(UInt32 *numMethods) throw(); + STDMETHOD(GetNumberOfMethods)(UInt32 *numMethods) throw() override; #endif - STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value) throw(); - STDMETHOD(CreateDecoder)(UInt32 index, const GUID *interfaceID, void **coder) throw(); - STDMETHOD(CreateEncoder)(UInt32 index, const GUID *interfaceID, void **coder) throw(); + STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value) throw() override; + STDMETHOD(CreateDecoder)(UInt32 index, const GUID *interfaceID, void **coder) throw() override; + STDMETHOD(CreateEncoder)(UInt32 index, const GUID *interfaceID, void **coder) throw() override; void InitData(); private: diff --git a/src/7ZipInStreamWrapper.h b/src/7ZipInStreamWrapper.h index 6cf0610..232ab19 100644 --- a/src/7ZipInStreamWrapper.h +++ b/src/7ZipInStreamWrapper.h @@ -13,10 +13,10 @@ class C7ZipInStreamWrapper: public: Z7_COM_UNKNOWN_IMP_2(IInStream, IStreamGetSize) - STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize) throw(); - STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) throw(); + STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize) throw() override; + STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) throw() override; - STDMETHOD(GetSize)(UInt64 *size) throw(); + STDMETHOD(GetSize)(UInt64 *size) throw() override; private: C7ZipInStream * m_pInStream; From 6b4b0b136556db87d9912b6cf85f824dd8abcf91 Mon Sep 17 00:00:00 2001 From: "Azamat H. Hackimov" Date: Wed, 22 Jul 2026 11:29:32 +0300 Subject: [PATCH 04/12] Fix -Werror=unused-result compilation failure --- src/OSFunctions_UnixLike.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OSFunctions_UnixLike.cpp b/src/OSFunctions_UnixLike.cpp index 583b487..3f6c6d5 100644 --- a/src/OSFunctions_UnixLike.cpp +++ b/src/OSFunctions_UnixLike.cpp @@ -122,13 +122,13 @@ int myselect(const struct dirent * pDir ) { closedir( pTmpDir ); - (void)chdir( szEntryName ); + int result = chdir( szEntryName ); struct dirent **namelist = NULL; scandir( ".",&namelist,myselect,alphasort ); - (void)chdir( ".." ); + result = chdir( ".." ); } return 0; From 81235fdf9d69ce85569bfecd73fdfab9e1e41afc Mon Sep 17 00:00:00 2001 From: "Azamat H. Hackimov" Date: Wed, 22 Jul 2026 12:23:26 +0300 Subject: [PATCH 05/12] Avoid using includes from 7zip sources in lib7zip.h Copying (U)Int64 types definitions from 7zip header. This allows to use and install lib7zip independently of 7zip sources. --- src/lib7zip.h | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/lib7zip.h b/src/lib7zip.h index 7404489..e45e42c 100644 --- a/src/lib7zip.h +++ b/src/lib7zip.h @@ -14,8 +14,29 @@ #include #include -// Include 7zip types -#include "CPP/Common/MyTypes.h" +// Copy from "CPP/Common/MyTypes.h" +#ifdef Z7_DECL_Int64_AS_long + +typedef long Int64; +typedef unsigned long UInt64; + +#else + +#if (defined(_MSC_VER) || defined(__BORLANDC__)) && !defined(__clang__) +typedef __int64 Int64; +typedef unsigned __int64 UInt64; +#else +#if defined(__clang__) || defined(__GNUC__) +#include +typedef int64_t Int64; +typedef uint64_t UInt64; +#else +typedef long long int Int64; +typedef unsigned long long int UInt64; +#endif +#endif + +#endif #ifndef _WIN32 #ifndef __int64 From af0af94f072e2229e9c7542378c6bc762a1015af Mon Sep 17 00:00:00 2001 From: "Azamat H. Hackimov" Date: Wed, 22 Jul 2026 12:36:29 +0300 Subject: [PATCH 06/12] Add installation targets Build only one type of library (STATIC/SHARED) at same time. In order to get both types users should use CMake Presets or MultiConfig generators. --- CMakeLists.txt | 14 +++++--------- README.md | 15 +++++++-------- src/CMakeLists.txt | 41 ++++++++++++++++++++++++----------------- 3 files changed, 36 insertions(+), 34 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9506f77..a9b1357 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,8 @@ SET(CMAKE_CXX_STANDARD 14) SET(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_POSITION_INDEPENDENT_CODE ON) +INCLUDE(GNUInstallDirs) + IF (APPLE) SET(CMAKE_MACOSX_RPATH 1) SET(CMAKE_PREFIX_PATH /usr/local) @@ -34,16 +36,10 @@ IF (LIB7ZIP_WARNING_AS_ERROR) SET(CMAKE_COMPILE_WARNING_AS_ERROR ON) ENDIF () -SET(SEVENZIP_INCLUDE_PATH - "${SEVENZIP_SOURCE_DIR}" - "${SEVENZIP_SOURCE_DIR}/CPP" - "${SEVENZIP_SOURCE_DIR}/CPP/Common" - "${SEVENZIP_SOURCE_DIR}/CPP/Windows" - "${SEVENZIP_SOURCE_DIR}/C" - "${PROJECT_SOURCE_DIR}/src" -) - ADD_SUBDIRECTORY(src) IF (LIB7ZIP_ENABLE_TESTING) ADD_SUBDIRECTORY(test) ENDIF () + +# Install +INSTALL(FILES README.md DESTINATION ${CMAKE_INSTALL_DOCDIR}) diff --git a/README.md b/README.md index 7c10894..5e86d87 100644 --- a/README.md +++ b/README.md @@ -126,14 +126,13 @@ export LD_LIBRARY_PATH=./build/src:$LD_LIBRARY_PATH ## 🎯 Project Status -| Component | Status | Notes | -|-----------|--------|-------| -| **Core Library** | ✅ **Ready** | Fully functional with 7-Zip 25.0 | -| **Static Library** | ✅ **Ready** | Successfully builds with CMake | -| **Shared Library** | ✅ **Ready** | Optional, enable with -DBUILD_SHARED_LIB=ON | -| **COM Interfaces** | ✅ **Ready** | All interfaces updated for 7-Zip 25.0 | -| **API Compatibility** | ✅ **Ready** | Backward compatible API maintained | -| **Test Programs** | ⚠️ **Partial** | Core library works, tests need minor updates | +| Component | Status | Notes | +|---------------------------|----------------|----------------------------------------------| +| **Core Library** | ✅ **Ready** | Fully functional with 7-Zip 25.0 | +| **Shared/Static Library** | ✅ **Ready** | Build with -DLIB7ZIP_BUILD_SHARED_LIB=ON/OFF | +| **COM Interfaces** | ✅ **Ready** | All interfaces updated for 7-Zip 25.0 | +| **API Compatibility** | ✅ **Ready** | Backward compatible API maintained | +| **Test Programs** | ⚠️ **Partial** | Core library works, tests need minor updates | ## 🔍 Verification diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d7b6bb4..f81debb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -35,27 +35,34 @@ SET(lib7zip_NODIST_SOURCES ${SEVENZIP_SOURCE_DIR}/CPP/Windows/PropVariant.cpp ) -ADD_LIBRARY(lib7zip STATIC ${lib7zip_src} - ${lib7zip_NODIST_SOURCES} -) +IF (LIB7ZIP_BUILD_SHARED_LIB) + ADD_LIBRARY(lib7zip SHARED ${lib7zip_src} ${lib7zip_NODIST_SOURCES}) +ELSE () + ADD_LIBRARY(lib7zip STATIC ${lib7zip_src} ${lib7zip_NODIST_SOURCES}) +ENDIF () SET_TARGET_PROPERTIES(lib7zip PROPERTIES OUTPUT_NAME "7zip" ) -TARGET_INCLUDE_DIRECTORIES(lib7zip PRIVATE - "${SEVENZIP_INCLUDE_PATH}" +TARGET_INCLUDE_DIRECTORIES(lib7zip + PRIVATE "${SEVENZIP_SOURCE_DIR}" + PUBLIC + "$" + "$" ) -IF (LIB7ZIP_BUILD_SHARED_LIB) - ADD_LIBRARY(lib7zip_shared SHARED ${lib7zip_src} - ${lib7zip_NODIST_SOURCES} - ) - SET_TARGET_PROPERTIES(lib7zip_shared PROPERTIES - OUTPUT_NAME "7zip" - ) - - TARGET_INCLUDE_DIRECTORIES(lib7zip_shared PRIVATE - "${SEVENZIP_INCLUDE_PATH}" - ) -ENDIF () +# Installation +INSTALL(TARGETS lib7zip + EXPORT lib7zipTargets + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} +) +INSTALL(FILES lib7zip.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) +INSTALL(EXPORT lib7zipTargets + FILE lib7zipTargets.cmake + NAMESPACE lib7zip:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/lib7zip +) From b3c6529fb227afd53193f1a0ca6512ccee5f956e Mon Sep 17 00:00:00 2001 From: "Azamat H. Hackimov" Date: Wed, 22 Jul 2026 13:26:02 +0300 Subject: [PATCH 07/12] Add GitHub Actions build Add CI pipeline for build testing. --- .github/workflows/build.yml | 53 +++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..255282a --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,53 @@ +name: build + +on: + push: + tags: + - 'v*' + branches: + - master + pull_request: + branches: + - master + +jobs: + build-linux: + runs-on: ${{ matrix.config.os }} + name: 'Build (${{ matrix.config.cxx }}, ${{ matrix.type }}, SHARED=${{ matrix.build_shared }})' + strategy: + fail-fast: false + matrix: + config: + - { os: "ubuntu-latest", cxx: "g++" } + - { os: "ubuntu-latest", cxx: "clang++" } + - { os: "windows-latest", cxx: "cl" } + type: + - "Debug" + - "Release" + build_shared: + - "ON" + - "OFF" + steps: + - name: "Checkout" + uses: actions/checkout@v4 + with: + submodules: 'true' + + - name: "Prepare Windows environment" + uses: ilammy/msvc-dev-cmd@v1 + if: ${{ matrix.config.os == 'windows-latest' }} + with: + arch: win64 + + - name: "Install dependencies" + if: ${{ matrix.config.os == 'ubuntu-latest' }} + run: | + sudo apt-get update + sudo apt-get install -y 7zip + + - name: "Build with ${{ matrix.config.cxx }}" + env: + CXX: ${{ matrix.config.cxx }} + run: | + cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=${{ matrix.type }} -DLIB7ZIP_BUILD_SHARED_LIB=${{ matrix.build_shared }} + cmake --build build -j2 From a9d71f6e03ac258c6e0724d60e315e4353d7f9e7 Mon Sep 17 00:00:00 2001 From: "Azamat H. Hackimov" Date: Wed, 22 Jul 2026 13:47:25 +0300 Subject: [PATCH 08/12] Set -DUNICODE -D_UNICODE for MSVC builds --- src/CMakeLists.txt | 4 ++++ test/CMakeLists.txt | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f81debb..a96f61d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -45,6 +45,10 @@ SET_TARGET_PROPERTIES(lib7zip PROPERTIES OUTPUT_NAME "7zip" ) +TARGET_COMPILE_DEFINITIONS(lib7zip PUBLIC + $<$:UNICODE _UNICODE> +) + TARGET_INCLUDE_DIRECTORIES(lib7zip PRIVATE "${SEVENZIP_SOURCE_DIR}" PUBLIC diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 7f8bd58..fa565a4 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -29,6 +29,10 @@ FOREACH (f ${test_src}) "${SEVENZIP_INCLUDE_PATH}" ) + TARGET_COMPILE_DEFINITIONS(${test_target_name} PRIVATE + $<$:UNICODE _UNICODE> + ) + TARGET_LINK_LIBRARIES(${test_target_name} lib7zip ${CMAKE_DL_LIBS} From 81c6eb68f77409d7b504a80ad9245ae325ed184c Mon Sep 17 00:00:00 2001 From: "Azamat H. Hackimov" Date: Wed, 22 Jul 2026 13:52:15 +0300 Subject: [PATCH 09/12] Move include "CPP/Windows/Defs.h" out of scope !defined(_WIN32) Fixing building on Windows platform. --- src/HelperFuncs.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/HelperFuncs.cpp b/src/HelperFuncs.cpp index b39aa62..be7ea71 100644 --- a/src/HelperFuncs.cpp +++ b/src/HelperFuncs.cpp @@ -9,12 +9,12 @@ #if !defined(_WIN32) && !defined(_OS2) #include "CPP/Common/StdAfx.h" -#include "CPP/Windows/Defs.h" #include "CPP/7zip/MyVersion.h" #endif #include "C/7zVersion.h" #include "CPP/7zip/Archive/IArchive.h" +#include "CPP/Windows/Defs.h" #include "CPP/Windows/PropVariant.h" #include "CPP/Common/MyCom.h" #include "CPP/7zip/ICoder.h" From 7238edbb6f47fc2a128a984c2e835475c4f247f7 Mon Sep 17 00:00:00 2001 From: "Azamat H. Hackimov" Date: Wed, 22 Jul 2026 14:03:07 +0300 Subject: [PATCH 10/12] Fix building errors on MSVC Use "%hs" for wprintf() on wstring. Use "%lld" for wprintf() on UInt64 types. --- test/Test7Zip.cpp | 10 +++++----- test/Test7Zip2.cpp | 10 +++++----- test/Test7ZipCryptFileName.cpp | 14 +++++++------- test/Test7ZipDmg.cpp | 6 +++--- test/Test7ZipMulti.cpp | 6 +++--- test/Test7ZipRar5.cpp | 10 +++++----- test/Test7ZipSignature.cpp | 10 +++++----- test/test7zipprops.cpp | 12 ++++++------ test/test_archive.cpp | 12 ++++++------ 9 files changed, 45 insertions(+), 45 deletions(-) diff --git a/test/Test7Zip.cpp b/test/Test7Zip.cpp index cc5b7d2..b5a8bd3 100644 --- a/test/Test7Zip.cpp +++ b/test/Test7Zip.cpp @@ -18,7 +18,7 @@ class TestInStream : public C7ZipInStream m_strFileExt(L"7z") { - wprintf(L"fileName.c_str(): %s\n", fileName.c_str()); + wprintf(L"fileName.c_str(): %hs\n", fileName.c_str()); m_pFile = fopen(fileName.c_str(), "rb"); if (m_pFile) { fseek(m_pFile, 0, SEEK_END); @@ -44,7 +44,7 @@ class TestInStream : public C7ZipInStream wprintf(L"Ext:%ls\n", m_strFileExt.c_str()); } else { - wprintf(L"fileName.c_str(): %s cant open\n", fileName.c_str()); + wprintf(L"fileName.c_str(): %hs cant open\n", fileName.c_str()); } } @@ -183,7 +183,7 @@ class TestOutStream : public C7ZipOutStream virtual int SetSize(UInt64 size) { - wprintf(L"SetFileSize:%ld\n", size); + wprintf(L"SetFileSize:%lld\n", size); return 0; } }; @@ -276,7 +276,7 @@ int main(int argc, char * argv[]) wprintf(L"\n\nGetProperty:%d %ls\n", (int)index, index_names[(int)index]); - wprintf(L"UInt64 result:%ls val=%ld\n", + wprintf(L"UInt64 result:%ls val=%lld\n", result ? L"true" : L"false", val); @@ -294,7 +294,7 @@ int main(int argc, char * argv[]) result = pArchiveItem->GetFileTimeProperty(index, val); - wprintf(L"FileTime result:%ls val=%ld\n", + wprintf(L"FileTime result:%ls val=%lld\n", result ? L"true" : L"false", val); } diff --git a/test/Test7Zip2.cpp b/test/Test7Zip2.cpp index 6ed1f23..163aee3 100644 --- a/test/Test7Zip2.cpp +++ b/test/Test7Zip2.cpp @@ -18,7 +18,7 @@ class TestInStream : public C7ZipInStream m_strFileExt(L"zip") { - wprintf(L"fileName.c_str(): %s\n", fileName.c_str()); + wprintf(L"fileName.c_str(): %hs\n", fileName.c_str()); m_pFile = fopen(fileName.c_str(), "rb"); if (m_pFile) { fseek(m_pFile, 0, SEEK_END); @@ -44,7 +44,7 @@ class TestInStream : public C7ZipInStream wprintf(L"Ext:%ls\n", m_strFileExt.c_str()); } else { - wprintf(L"fileName.c_str(): %s cant open\n", fileName.c_str()); + wprintf(L"fileName.c_str(): %hs cant open\n", fileName.c_str()); } } @@ -183,7 +183,7 @@ class TestOutStream : public C7ZipOutStream virtual int SetSize(UInt64 size) { - wprintf(L"SetFileSize:%ld\n", size); + wprintf(L"SetFileSize:%lld\n", size); return 0; } }; @@ -276,7 +276,7 @@ int main(int argc, char * argv[]) wprintf(L"\n\nGetProperty:%d %ls\n", (int)index, index_names[(int)index]); - wprintf(L"UInt64 result:%ls val=%ld\n", + wprintf(L"UInt64 result:%ls val=%lld\n", result ? L"true" : L"false", val); @@ -294,7 +294,7 @@ int main(int argc, char * argv[]) result = pArchiveItem->GetFileTimeProperty(index, val); - wprintf(L"FileTime result:%ls val=%ld\n", + wprintf(L"FileTime result:%ls val=%lld\n", result ? L"true" : L"false", val); } diff --git a/test/Test7ZipCryptFileName.cpp b/test/Test7ZipCryptFileName.cpp index 5f81816..270a633 100644 --- a/test/Test7ZipCryptFileName.cpp +++ b/test/Test7ZipCryptFileName.cpp @@ -18,7 +18,7 @@ class TestInStream : public C7ZipInStream m_strFileExt(L"7z") { - wprintf(L"fileName.c_str(): %s\n", fileName.c_str()); + wprintf(L"fileName.c_str(): %hs\n", fileName.c_str()); m_pFile = fopen(fileName.c_str(), "rb"); if (m_pFile) { fseek(m_pFile, 0, SEEK_END); @@ -44,7 +44,7 @@ class TestInStream : public C7ZipInStream wprintf(L"Ext:%ls\n", m_strFileExt.c_str()); } else { - wprintf(L"fileName.c_str(): %s cant open\n", fileName.c_str()); + wprintf(L"fileName.c_str(): %hs cant open\n", fileName.c_str()); } } @@ -183,7 +183,7 @@ class TestOutStream : public C7ZipOutStream virtual int SetSize(UInt64 size) { - wprintf(L"SetFileSize:%ld\n", size); + wprintf(L"SetFileSize:%lld\n", size); return 0; } }; @@ -275,7 +275,7 @@ int _tmain(int argc, _TCHAR* argv[]) wprintf(L"\n\nGetProperty:%d %ls\n", (int)index, index_names[(int)index]); - wprintf(L"UInt64 result:%ls val=%ld\n", + wprintf(L"UInt64 result:%ls val=%lld\n", result ? L"true" : L"false", val); @@ -293,7 +293,7 @@ int _tmain(int argc, _TCHAR* argv[]) result = pArchive->GetFileTimeProperty(index, val); - wprintf(L"FileTime result:%ls val=%ld\n", + wprintf(L"FileTime result:%ls val=%lld\n", result ? L"true" : L"false", val); } @@ -321,7 +321,7 @@ int _tmain(int argc, _TCHAR* argv[]) wprintf(L"\n\nGetProperty:%d %ls\n", (int)index, index_names[(int)index]); - wprintf(L"UInt64 result:%ls val=%ld\n", + wprintf(L"UInt64 result:%ls val=%lld\n", result ? L"true" : L"false", val); @@ -339,7 +339,7 @@ int _tmain(int argc, _TCHAR* argv[]) result = pArchiveItem->GetFileTimeProperty(index, val); - wprintf(L"FileTime result:%ls val=%ld\n", + wprintf(L"FileTime result:%ls val=%lld\n", result ? L"true" : L"false", val); } diff --git a/test/Test7ZipDmg.cpp b/test/Test7ZipDmg.cpp index 4da11df..40e1912 100644 --- a/test/Test7ZipDmg.cpp +++ b/test/Test7ZipDmg.cpp @@ -18,7 +18,7 @@ class TestInStream : public C7ZipInStream m_strFileExt(L"7z") { - wprintf(L"fileName.c_str(): %s\n", fileName.c_str()); + wprintf(L"fileName.c_str(): %hs\n", fileName.c_str()); m_pFile = fopen(fileName.c_str(), "rb"); if (m_pFile) { fseek(m_pFile, 0, SEEK_END); @@ -44,7 +44,7 @@ class TestInStream : public C7ZipInStream // wprintf(L"Ext:%ls\n", m_strFileExt.c_str()); } else { - wprintf(L"fileName.c_str(): %s cant open\n", fileName.c_str()); + wprintf(L"fileName.c_str(): %hs cant open\n", fileName.c_str()); } } @@ -182,7 +182,7 @@ class TestOutStream : public C7ZipOutStream virtual int SetSize(UInt64 size) { - wprintf(L"SetFileSize:%ld\n", size); + wprintf(L"SetFileSize:%lld\n", size); return 0; } }; diff --git a/test/Test7ZipMulti.cpp b/test/Test7ZipMulti.cpp index 5cd846b..e6ce415 100644 --- a/test/Test7ZipMulti.cpp +++ b/test/Test7ZipMulti.cpp @@ -90,7 +90,7 @@ class TestInStream : public C7ZipInStream { wprintf(L"Seek\n"); int result = fseek(m_pFile, (long)offset, seekOrigin); - wprintf(L"Seek:%ld %ld\n", offset, result); + wprintf(L"Seek:%lld %d\n", offset, result); if (!result) { if (newPosition) @@ -149,7 +149,7 @@ class TestMultiVolumes : public C7ZipMultiVolumes fclose(m_pFile); m_pFile = NULL; string f = narrow(volumeName); - wprintf(L"narrow volume:%s\n", f.c_str()); + wprintf(L"narrow volume:%hs\n", f.c_str()); m_pFile = fopen(f.c_str(), "rb"); @@ -254,7 +254,7 @@ class TestOutStream : public C7ZipOutStream virtual int SetSize(UInt64 size) { - wprintf(L"SetFileSize:%ld\n", size); + wprintf(L"SetFileSize:%lld\n", size); return 0; } }; diff --git a/test/Test7ZipRar5.cpp b/test/Test7ZipRar5.cpp index 1a5dbd8..4cecdea 100644 --- a/test/Test7ZipRar5.cpp +++ b/test/Test7ZipRar5.cpp @@ -18,7 +18,7 @@ class TestInStream : public C7ZipInStream m_strFileExt(L"rar") { - wprintf(L"fileName.c_str(): %s\n", fileName.c_str()); + wprintf(L"fileName.c_str(): %hs\n", fileName.c_str()); m_pFile = fopen(fileName.c_str(), "rb"); if (m_pFile) { fseek(m_pFile, 0, SEEK_END); @@ -44,7 +44,7 @@ class TestInStream : public C7ZipInStream wprintf(L"Ext:%ls\n", m_strFileExt.c_str()); } else { - wprintf(L"fileName.c_str(): %s cant open\n", fileName.c_str()); + wprintf(L"fileName.c_str(): %hs cant open\n", fileName.c_str()); } } @@ -183,7 +183,7 @@ class TestOutStream : public C7ZipOutStream virtual int SetSize(UInt64 size) { - wprintf(L"SetFileSize:%ld\n", size); + wprintf(L"SetFileSize:%lld\n", size); return 0; } }; @@ -276,7 +276,7 @@ int main(int argc, char * argv[]) wprintf(L"\n\nGetProperty:%d %ls\n", (int)index, index_names[(int)index]); - wprintf(L"UInt64 result:%ls val=%ld\n", + wprintf(L"UInt64 result:%ls val=%lld\n", result ? L"true" : L"false", val); @@ -294,7 +294,7 @@ int main(int argc, char * argv[]) result = pArchiveItem->GetFileTimeProperty(index, val); - wprintf(L"FileTime result:%ls val=%ld\n", + wprintf(L"FileTime result:%ls val=%lld\n", result ? L"true" : L"false", val); } diff --git a/test/Test7ZipSignature.cpp b/test/Test7ZipSignature.cpp index e38788c..540afa2 100644 --- a/test/Test7ZipSignature.cpp +++ b/test/Test7ZipSignature.cpp @@ -18,7 +18,7 @@ class TestInStream : public C7ZipInStream m_strFileExt(L"7z") { - wprintf(L"fileName.c_str(): %s\n", fileName.c_str()); + wprintf(L"fileName.c_str(): %hs\n", fileName.c_str()); m_pFile = fopen(fileName.c_str(), "rb"); if (m_pFile) { fseek(m_pFile, 0, SEEK_END); @@ -44,7 +44,7 @@ class TestInStream : public C7ZipInStream wprintf(L"Ext:%ls\n", m_strFileExt.c_str()); } else { - wprintf(L"fileName.c_str(): %s cant open\n", fileName.c_str()); + wprintf(L"fileName.c_str(): %hs cant open\n", fileName.c_str()); } } @@ -183,7 +183,7 @@ class TestOutStream : public C7ZipOutStream virtual int SetSize(UInt64 size) { - wprintf(L"SetFileSize:%ld\n", size); + wprintf(L"SetFileSize:%lld\n", size); return 0; } }; @@ -276,7 +276,7 @@ int main(int argc, char * argv[]) wprintf(L"\n\nGetProperty:%d %ls\n", (int)index, index_names[(int)index]); - wprintf(L"UInt64 result:%ls val=%ld\n", + wprintf(L"UInt64 result:%ls val=%lld\n", result ? L"true" : L"false", val); @@ -294,7 +294,7 @@ int main(int argc, char * argv[]) result = pArchiveItem->GetFileTimeProperty(index, val); - wprintf(L"FileTime result:%ls val=%ld\n", + wprintf(L"FileTime result:%ls val=%lld\n", result ? L"true" : L"false", val); } diff --git a/test/test7zipprops.cpp b/test/test7zipprops.cpp index 51596c0..a4d01f2 100644 --- a/test/test7zipprops.cpp +++ b/test/test7zipprops.cpp @@ -29,7 +29,7 @@ class TestInStream : public C7ZipInStream fseek(m_pFile, 0, SEEK_SET); } else { - wprintf(L"fileName.c_str(): %s cant open\n", fileName.c_str()); + wprintf(L"fileName.c_str(): %hs cant open\n", fileName.c_str()); } } @@ -164,7 +164,7 @@ int main(int argc, char * argv[]) wprintf(L"\n\nGetArciveProperty:%d %ls\n", (int)index, index_names[(int)index]); - wprintf(L"Archive UInt64 result:%ls val=%ld\n", + wprintf(L"Archive UInt64 result:%ls val=%lld\n", result ? L"true" : L"false", val); @@ -182,7 +182,7 @@ int main(int argc, char * argv[]) result = pArchive->GetFileTimeProperty(index, val); - wprintf(L"Archive FileTime result:%ls val=%ld\n", + wprintf(L"Archive FileTime result:%ls val=%lld\n", result ? L"true" : L"false", val); } @@ -212,7 +212,7 @@ int main(int argc, char * argv[]) wprintf(L"\n\nGetProperty:%d %ls\n", (int)index, index_names[(int)index]); - wprintf(L"UInt64 result:%ls val=%ld\n", + wprintf(L"UInt64 result:%ls val=%lld\n", result ? L"true" : L"false", val); @@ -230,7 +230,7 @@ int main(int argc, char * argv[]) result = pArchiveItem->GetFileTimeProperty(index, val); - wprintf(L"FileTime result:%ls val=%ld\n", + wprintf(L"FileTime result:%ls val=%lld\n", result ? L"true" : L"false", val); } @@ -238,7 +238,7 @@ int main(int argc, char * argv[]) } } else { - wprintf(L"open archive %s fail\n", files[i]); + wprintf(L"open archive %hs fail\n", files[i]); } } diff --git a/test/test_archive.cpp b/test/test_archive.cpp index 58fb6ef..1223043 100644 --- a/test/test_archive.cpp +++ b/test/test_archive.cpp @@ -18,7 +18,7 @@ class TestInStream : public C7ZipInStream m_strFileExt(L"zip") { - wprintf(L"fileName.c_str(): %s\n", fileName.c_str()); + wprintf(L"fileName.c_str(): %hs\n", fileName.c_str()); m_pFile = fopen(fileName.c_str(), "rb"); if (m_pFile) { fseek(m_pFile, 0, SEEK_END); @@ -44,7 +44,7 @@ class TestInStream : public C7ZipInStream wprintf(L"Ext:%ls\n", m_strFileExt.c_str()); } else { - wprintf(L"fileName.c_str(): %s cant open\n", fileName.c_str()); + wprintf(L"fileName.c_str(): %hs cant open\n", fileName.c_str()); } } @@ -183,7 +183,7 @@ class TestOutStream : public C7ZipOutStream virtual int SetSize(UInt64 size) { - wprintf(L"SetFileSize:%ld\n", size); + wprintf(L"SetFileSize:%lld\n", size); return 0; } }; @@ -281,7 +281,7 @@ int main(int argc, char * argv[]) wprintf(L"\n\nGetProperty:%d %ls\n", (int)index, index_names[(int)index]); - wprintf(L"UInt64 result:%ls val=%ld\n", + wprintf(L"UInt64 result:%ls val=%lld\n", result ? L"true" : L"false", val); @@ -299,7 +299,7 @@ int main(int argc, char * argv[]) result = pArchiveItem->GetFileTimeProperty(index, val); - wprintf(L"FileTime result:%ls val=%ld\n", + wprintf(L"FileTime result:%ls val=%lld\n", result ? L"true" : L"false", val); } @@ -309,7 +309,7 @@ int main(int argc, char * argv[]) }//for } else { - wprintf(L"open archive %s fail\n", argv[1]); + wprintf(L"open archive %hs fail\n", argv[1]); } if (pArchive != NULL) From 4dea01507e8a6cb617823c578afce6c300372998 Mon Sep 17 00:00:00 2001 From: "Azamat H. Hackimov" Date: Wed, 22 Jul 2026 15:03:43 +0300 Subject: [PATCH 11/12] Fix building of test_archive.cpp Convert input TCHAR* parameter into std::string. --- test/test_archive.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/test/test_archive.cpp b/test/test_archive.cpp index 1223043..0d662dd 100644 --- a/test/test_archive.cpp +++ b/test/test_archive.cpp @@ -250,10 +250,18 @@ int main(int argc, char * argv[]) } C7ZipArchive * pArchive = NULL; +#ifdef _WIN32 + // Convert from TCHAR* + int sizeNeed = WideCharToMultiByte(CP_UTF8, 0, argv[1], -1, NULL, 0, NULL, NULL); + std::string input(sizeNeed - 1, 0); + WideCharToMultiByte(CP_UTF8, 0, argv[1], -1, &input[0], sizeNeed, NULL, NULL); +#else + std::string input = argv[1]; +#endif - TestInStream stream(argv[1]); + TestInStream stream(input); TestOutStream oStream("TestResult.txt"); - if (lib.OpenArchive(&stream, &pArchive, true)) { + if (lib.OpenArchive(&stream, &pArchive, true)) { unsigned int numItems = 0; pArchive->GetItemCount(&numItems); @@ -307,9 +315,8 @@ int main(int argc, char * argv[]) pArchive->Extract(pArchiveItem, &oStream); } //if }//for - } - else { - wprintf(L"open archive %hs fail\n", argv[1]); + } else { + wprintf(L"open archive %hs fail\n", input.c_str()); } if (pArchive != NULL) From ee824bfe7d6f0c9c56511c7e35ac4ff57cbc704d Mon Sep 17 00:00:00 2001 From: "Azamat H. Hackimov" Date: Wed, 22 Jul 2026 15:45:05 +0300 Subject: [PATCH 12/12] Build only static on Windows lib7zip not ready yet for Windows DLL linking. --- .github/workflows/build.yml | 9 ++++++--- CMakeLists.txt | 2 +- README.md | 6 +++--- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 255282a..f1a3b80 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,9 +11,9 @@ on: - master jobs: - build-linux: + build-all: runs-on: ${{ matrix.config.os }} - name: 'Build (${{ matrix.config.cxx }}, ${{ matrix.type }}, SHARED=${{ matrix.build_shared }})' + name: 'Build on ${{ matrix.config.os }} (${{ matrix.config.cxx }}, ${{ matrix.type }}, SHARED=${{ matrix.build_shared }})' strategy: fail-fast: false matrix: @@ -27,9 +27,12 @@ jobs: build_shared: - "ON" - "OFF" + exclude: + - config: { os: "windows-latest", cxx: "cl" } + build_shared: "ON" steps: - name: "Checkout" - uses: actions/checkout@v4 + uses: actions/checkout@v7 with: submodules: 'true' diff --git a/CMakeLists.txt b/CMakeLists.txt index a9b1357..1989363 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,7 @@ IF (NOT CMAKE_BUILD_TYPE) ENDIF () SET(SEVENZIP_SOURCE_DIR "${PROJECT_SOURCE_DIR}/third_party/7zip" CACHE STRING "Location of 7zip sources") -OPTION(LIB7ZIP_BUILD_SHARED_LIB "Build shared library" OFF) +OPTION(LIB7ZIP_BUILD_SHARED_LIB "Build shared library (only for *nix)" OFF) OPTION(LIB7ZIP_ENABLE_TESTING "Enable testing" ${PROJECT_IS_TOP_LEVEL}) OPTION(LIB7ZIP_WARNING_AS_ERROR "Threat all compiler warnings as errors" ${PROJECT_IS_TOP_LEVEL}) diff --git a/README.md b/README.md index 5e86d87..1856fb9 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ lib7zip is a C++ wrapper library for accessing 7-Zip archives programmatically. # Method 1: CMake with Submodule (Recommended) git submodule update --init --recursive mkdir build && cd build -cmake .. -DBUILD_SHARED_LIB=OFF +cmake .. make -j4 # Method 2: Direct compilation (Advanced users) @@ -46,7 +46,7 @@ git submodule update --init --recursive mkdir -p build && cd build # Configure (7-Zip source auto-detected from submodule) -cmake .. -DBUILD_SHARED_LIB=OFF +cmake .. # Build library make -j4 @@ -129,7 +129,7 @@ export LD_LIBRARY_PATH=./build/src:$LD_LIBRARY_PATH | Component | Status | Notes | |---------------------------|----------------|----------------------------------------------| | **Core Library** | ✅ **Ready** | Fully functional with 7-Zip 25.0 | -| **Shared/Static Library** | ✅ **Ready** | Build with -DLIB7ZIP_BUILD_SHARED_LIB=ON/OFF | +| **Shared/Static Library** | ⚠️ **Partial** | Windows supports only static linking | | **COM Interfaces** | ✅ **Ready** | All interfaces updated for 7-Zip 25.0 | | **API Compatibility** | ✅ **Ready** | Backward compatible API maintained | | **Test Programs** | ⚠️ **Partial** | Core library works, tests need minor updates |