Giter VIP home page Giter VIP logo

Comments (10)

rikyoz avatar rikyoz commented on June 12, 2024 1

I see. Thank you for the reproducer!
Unfortunately, the obvious fix of using #ifndef _WIN32 instead of #ifndef _MSC_VER breaks linking other programs:

libbit7z64_d.a(bufferextractcallback.cpp.obj):bufferextractcallback.cpp:(.rdata$.refptr.IID_IUnknown[.refptr.IID_IUnknown]+0x0): undefined reference to `IID_IUnknown'
collect2.exe: error: ld returned 1 exit status

I remember fixing this exact issue some years ago (24706ff), but that same fix is causing your issue.
So I'll need to come up with a better fix.
Thank you again for reporting this!

from bit7z.

rikyoz avatar rikyoz commented on June 12, 2024 1

I just pushed a fix to the branch hotfix/v4.0.6.
Basically, bit7z now defines IID_IUnknown inside a #ifndef _WIN32 condition, and more importantly, the CMakeLists.txt conditionally specifies the uuid library as a link dependency of bit7z, i.e.,

if( MINGW )
    target_link_libraries( ${LIB_TARGET} PUBLIC uuid )
endif()

This way, a project using bit7z will link against uuid, which will provide the (only) definition of IID_IUnknown.

from bit7z.

rikyoz avatar rikyoz commented on June 12, 2024 1

Released on v4.0.6.

from bit7z.

chapterjason avatar chapterjason commented on June 12, 2024

This fixes the issue for me.

File guids.hpp

 #ifndef _MSC_VER
+#ifndef __MINGW32__
 extern const GUID IID_IUnknown;
+#endif
 #endif

File guids.cpp

 #ifndef _MSC_VER
+#ifndef __MINGW32__
 const GUID IID_IUnknown = {
     0x00000000, 0x0000, 0x0000, { 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46 }
 };
+#endif
 #endif

from bit7z.

rikyoz avatar rikyoz commented on June 12, 2024

Hi!
This is actually quite strange, as I cannot replicate the issue:

  • Toolchain (MinGW bundled with CLion 2024.1 EAP, still MinGW 11.0 and GCC 13.1.0):
    image

  • CMakeLists.txt:

cmake_minimum_required( VERSION 3.28 )
project( test_uuid_mingw )

set( CMAKE_CXX_STANDARD 17 )

add_executable( test_uuid_mingw main.cpp )

include( cmake/Dependencies.cmake )

CPMAddPackage(
        NAME bit7z
        GIT_REPOSITORY "https://github.com/rikyoz/bit7z.git"
        GIT_TAG master
        OPTIONS
            "BIT7Z_BUILD_TESTS false"
            "BIT7Z_BUILD_DOCS false"
)

target_link_libraries(${PROJECT_NAME} PRIVATE bit7z)
  • CMake output:
-- CPM: Adding package bit7z@ (master)
-- Standard filesystem: NO (using ghc::filesystem)
-- Target Version: 
-- Compiler ID: GNU
-- Compiler Version: 13.1.0
-- Architecture: x64
-- Build Type: Debug
-- Language Standard for bit7z: C++14
-- Auto format detection: OFF
-- Regex matching extraction: OFF
-- Use std::byte: OFF
-- Use native string: OFF
-- Generate Position Independent Code: OFF
-- Disable Zip ASCII password check: OFF
-- Disable using std::filesystem: OFF
-- 7-zip version: 23.01
-- Build tests: false
-- Build docs: false
-- Auto prefix long paths: OFF
-- Use the default codepage: OFF
-- Path sanitization: OFF
-- CPM: bit7z: Adding package [email protected] (v23.01)
-- 7-zip source code available at [...]/test_uuid_mingw/cmake-build-debug-mingw-bundled/_deps/7-zip-src
-- CPM: bit7z: Adding package ghc_filesystem@0 (c0dcd0b090da7dffc74b124a6f164f54dbbb5ccb)
-- ghc::filesystem source code available at [...]/test_uuid_mingw/cmake-build-debug-mingw-bundled/_deps/ghc_filesystem-src
-- Enable sanitizers: OFF
-- Configuring done (5.2s)
-- Generating done (0.0s)
-- Build files have been written to: [...]/test_uuid_mingw/cmake-build-debug-mingw-bundled
  • Source code:
#include <bit7z/bit7zlibrary.hpp>
#include <bit7z/bitmemcompressor.hpp>

int main() {
    bit7z::Bit7zLibrary lib{};
    bit7z::BitMemCompressor compressor{lib, bit7z::BitFormat::Zip};
    compressor.compressFile({'h', 'e', 'l', 'l', 'o'}, "hello.zip");
    return 0;
}
  • Build output:
[...]
[57/61] Building CXX object _deps/bit7z-build/CMakeFiles/bit7z64.dir/src/internal/renameditem.cpp.obj
[58/61] Building CXX object _deps/bit7z-build/CMakeFiles/bit7z64.dir/src/internal/stringutil.cpp.obj
[59/61] Building CXX object _deps/bit7z-build/CMakeFiles/bit7z64.dir/src/internal/updatecallback.cpp.obj
[60/61] Linking CXX static library _deps\bit7z-src\lib\x64\libbit7z64_d.a
[61/61] Linking CXX executable test_uuid_mingw.exe

Build finished

from bit7z.

chapterjason avatar chapterjason commented on June 12, 2024

That is really strange, let me try to create a reproducer.

from bit7z.

chapterjason avatar chapterjason commented on June 12, 2024

This main file fails:

Usage of CLSID_* is the case #include <shobjidl.h> (https://learn.microsoft.com/en-us/windows/win32/api/shobjidl/)

#include <iostream>
#include <bit7z/bit7zlibrary.hpp>
#include <bit7z/bitmemcompressor.hpp>
#include <shobjidl.h>

int main() {
    const auto id = CLSID_FileOpenDialog;

    std::cout << id.Data1 << std::endl;

    bit7z::Bit7zLibrary lib{};
    bit7z::BitMemCompressor compressor{lib, bit7z::BitFormat::Zip};
    compressor.compressFile({'h', 'e', 'l', 'l', 'o'}, "hello.zip");
    return 0;
}

from bit7z.

chapterjason avatar chapterjason commented on June 12, 2024

Looks like this chain: #include <shobjidl.h> -> #include <ole2.h> -> #include <objbase.h> -> #include <combaseapi.h> -> #include <unknwnbase.h> which contains the IID_IUnknown

But I am not sure TBH, couldn't get a smaller reproducer.

from bit7z.

chapterjason avatar chapterjason commented on June 12, 2024

@rikyoz Works as expected! Thanks a lot. đŸ‘đŸŒ

from bit7z.

rikyoz avatar rikyoz commented on June 12, 2024

Perfect! You're welcome! đŸ‘đŸŒ

from bit7z.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.