c++android-studioandroid-studio-3.0android-studio-2.3

Need advice trying to get this app to build (running into 2 errors)


I'm trying to implement a feature found in Dolphin emulator into an unofficial build while learning about C++ coding on my own. Right now I was able to decrease the amount of errors to one file but these are the errors that I am getting for it.

First code errors are for this:

const u64 bytes_per_chunk = std::min(out_data_per_chunk, VolumeWii::GROUP_DATA_SIZE);
      const u64 total_size = blocks_in_this_group * VolumeWii::BLOCK_DATA_SIZE;
      const u64 data_offset = parameters.data_offset + write_offset_of_group;

I get an error that says (C:\Users\Desktop\dolphin\Source\Core\DiscIO\WIABlob.cpp:1465:39: error: no matching function for call to 'min') when referring to the " std::min " It appears in here as well:

const u64 bytes_to_write = std::min(bytes_to_write_total, VolumeWii::GROUP_DATA_SIZE);

Error = (C:\Users\Desktop\dolphin\Source\Core\DiscIO\WIABlob.cpp:1488:42: error: no matching function for call to 'min')

------------------------------------------------------------------------------

The next error I get (again all this is within the same .cpp file) is also from the same lines of code:

const u64 bytes_per_chunk = std::min(out_data_per_chunk, VolumeWii::GROUP_DATA_SIZE);
      const u64 total_size = blocks_in_this_group * VolumeWii::BLOCK_DATA_SIZE;
      const u64 data_offset = parameters.data_offset + write_offset_of_group;

and here too:

const u64 bytes_to_write = std::min(bytes_to_write_total, VolumeWii::GROUP_DATA_SIZE);

The error I get for the later set is [C:\Users\Desktop\dolphin\Source\Core\DiscIO\WIABlob.cpp:1465:21: error: default initialization of an object of const type 'const u64' (aka 'const unsigned long')] --> this is related/highlighted by the "bytes_to_write" line in Android Studio. Also appears lower down still related to another "bytes_to_write" line [C:\Users\Desktop\dolphin\Source\Core\DiscIO\WIABlob.cpp:1488:25: error: default initialization of an object of const type 'const u64' (aka 'const unsigned long')]

So far those are the 2 errors that stop me from building the app.

====================================================

Build errors:

In file included from ../../../../../../Core/DiscIO/WIABlob.cpp:5:
In file included from ../../../../../../Core\DiscIO/WIABlob.h:21:
In file included from ../../../../../../Core\DiscIO/WiiEncryptionCache.h:12:
../../../../../../Core\DiscIO/VolumeWii.h:91:3: warning: 'DiscIO::VolumeWii::CheckBlockIntegrity' hides overloaded virtual function [-Woverloaded-virtual]
  CheckBlockIntegrity(u64 block_index, const Partition &partition, const Partition partition1) const ;
  ^
../../../../../../Core\DiscIO/Volume.h:112:16: note: hidden overloaded virtual function 'DiscIO::Volume::CheckBlockIntegrity' declared here: different number of parameters (2 vs 3)
  virtual bool CheckBlockIntegrity(u64 block_index, const Partition& partition) const
               ^
In file included from ../../../../../../Core/DiscIO/WIABlob.cpp:5:
In file included from ../../../../../../Core\DiscIO/WIABlob.h:21:
In file included from ../../../../../../Core\DiscIO/WiiEncryptionCache.h:12:
../../../../../../Core\DiscIO/VolumeWii.h:141:10: warning: 'DiscIO::VolumeWii::CheckBlockIntegrity' hides overloaded virtual function [-Woverloaded-virtual]
    bool CheckBlockIntegrity(u64 block_index, const std::vector<u8> &encrypted_data,
         ^
../../../../../../Core\DiscIO/Volume.h:112:16: note: hidden overloaded virtual function 'DiscIO::Volume::CheckBlockIntegrity' declared here: different number of parameters (2 vs 3)
  virtual bool CheckBlockIntegrity(u64 block_index, const Partition& partition) const
               ^
../../../../../../Core/DiscIO/WIABlob.cpp:1465:39: error: no matching function for call to 'min'
          const u64 bytes_per_chunk = std::min(out_data_per_chunk, VolumeWii::GROUP_DATA_SIZE);
                                      ^~~~~~~~
C:/Android/SDK/ndk/21.3.6528147/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/c++/v1\algorithm:2532:1: note: candidate template ignored: deduced conflicting types for parameter '_Tp' ('unsigned long' vs. 'unsigned int')
min(const _Tp& __a, const _Tp& __b)
^
C:/Android/SDK/ndk/21.3.6528147/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/c++/v1\algorithm:2543:1: note: candidate template ignored: could not match 'initializer_list<type-parameter-0-0>' against 'unsigned long'
min(initializer_list<_Tp> __t, _Compare __comp)
^
C:/Android/SDK/ndk/21.3.6528147/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/c++/v1\algorithm:2523:1: note: candidate function template not viable: requires 3 arguments, but 2 were provided
min(const _Tp& __a, const _Tp& __b, _Compare __comp)
^
C:/Android/SDK/ndk/21.3.6528147/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/c++/v1\algorithm:2552:1: note: candidate function template not viable: requires single argument '__t', but 2 arguments were provided
min(initializer_list<_Tp> __t)
^
../../../../../../Core/DiscIO/WIABlob.cpp:1488:42: error: no matching function for call to 'min'
              const u64 bytes_to_write = std::min(bytes_to_write_total, VolumeWii::GROUP_DATA_SIZE);
                                         ^~~~~~~~
C:/Android/SDK/ndk/21.3.6528147/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/c++/v1\algorithm:2532:1: note: candidate template ignored: deduced conflicting types for parameter '_Tp' ('unsigned long' vs. 'unsigned int')
min(const _Tp& __a, const _Tp& __b)
^
C:/Android/SDK/ndk/21.3.6528147/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/c++/v1\algorithm:2543:1: note: candidate template ignored: could not match 'initializer_list<type-parameter-0-0>' against 'unsigned long'
min(initializer_list<_Tp> __t, _Compare __comp)
^
C:/Android/SDK/ndk/21.3.6528147/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/c++/v1\algorithm:2523:1: note: candidate function template not viable: requires 3 arguments, but 2 were provided
min(const _Tp& __a, const _Tp& __b, _Compare __comp)
^
C:/Android/SDK/ndk/21.3.6528147/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/c++/v1\algorithm:2552:1: note: candidate function template not viable: requires single argument '__t', but 2 arguments were provided
min(initializer_list<_Tp> __t)
^

IF you want to see the original code that I am using its from this .cpp file here: https://github.com/JosJuice/dolphin/blob/660d81a10b4a8ff9a61631e69fb93e9010bccbc0/Source/Core/DiscIO/WIABlob.cpp

I hope I can get any good advice to get through this issue and finally built the Apk (got stuck on this for weeks now)


Solution

  • Your error message should be pretty clear. The relevant part:

    ../../../../../../Core/DiscIO/WIABlob.cpp:1465:39: error: no matching function for call to 'min'
              const u64 bytes_per_chunk = std::min(out_data_per_chunk, VolumeWii::GROUP_DATA_SIZE);
                                          ^~~~~~~~
    C:/Android/SDK/ndk/21.3.6528147/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/c++/v1\algorithm:2532:1: note: candidate template ignored: deduced conflicting types for parameter '_Tp' ('unsigned long' vs. 'unsigned int')
    min(const _Tp& __a, const _Tp& __b)
    

    The key part is that you're passing different types to std::min, which isn't allowed (think about what the return type would be). You'll need to either convert one of your arguments to the other type, or you could be explicit about which version of std::min you want.

    The conversion would look like this:

    const u64 bytes_per_chunk = std::min(out_data_per_chunk, static_cast<unsigned long>(VolumeWii::GROUP_DATA_SIZE));
    

    The explicit call version would look like this:

    const u64 bytes_per_chunk = std::min<u64>(out_data_per_chunk, VolumeWii::GROUP_DATA_SIZE);