canonical / flutter-snap

GNU General Public License v3.0
18 stars 8 forks source link

Flutter installed with snap fails compiling C++ code #83

Open svonidze opened 2 years ago

svonidze commented 2 years ago

Initially I reported the issue on https://github.com/flutter/flutter/issues/106102. The issue was addressed by reinstalling snap flutter with git clone. Found solution here https://stackoverflow.com/questions/70149507/flutter-build-failed-for-android-bitmapexternalnativebuilddebug the guy had a different issue and solved with reinstalling as well.

Original description: I have some code written in C++ and used in the Flutter project, I cannot run nor build code on Linix Mint, works ok on Mac and Windows.

Getting this error on Linix Mint

  In file included from ../../../../src/main/opencv2/include/opencv2/core/cvstd_wrapper.hpp:11:
  /snap/flutter/current/usr/include/c++/8/memory:116:25: error: cast from pointer to smaller type 'uintptr_t' (aka 'unsigned int') loses information
    const auto __intptr = reinterpret_cast<uintptr_t>(__ptr);
                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

while trying to run/build the project. .../c++/8/memory:116:25 leads to the code

/**
 *  @brief Fit aligned storage in buffer.
 *
 *  [ptr.align]
 *
 *  This function tries to fit @a __size bytes of storage with alignment ...
 */
inline void*
align(size_t __align, size_t __size, void*& __ptr, size_t& __space) noexcept
{
  const auto __intptr = reinterpret_cast<uintptr_t>(__ptr);   // <--- fails here
  const auto __aligned = (__intptr - 1u + __align) & -__align;
  const auto __diff = __aligned - __intptr;
  if ((__size + __diff) > __space)
    return nullptr;
  else
    {
      __space -= __diff;
      return __ptr = reinterpret_cast<void*>(__aligned);
    }
}

Full error log

Execution failed for task ':project_name_ffi:buildCMakeRelWithDebInfo[arm64-v8a]'.
> Build command failed.
  Error while executing process /home/sergey/Android/Sdk/cmake/3.18.1/bin/ninja with arguments {-C /home/sergey/projects/company_name/project_name/packages/project_name_ffi/android/.cxx/RelWithDebInfo/1v1k334p/arm64-v8a native-lib}
  ninja: Entering directory `/home/sergey/projects/company_name/project_name/packages/project_name_ffi/android/.cxx/RelWithDebInfo/1v1k334p/arm64-v8a'
  [1/4] Building CXX object CMakeFiles/native-lib.dir/home/sergey/projects/company_name/project_name/packages/project_name_ffi/cpp/general/general_funtion.cpp.o
  clang++: warning: -lGLESv2: 'linker' input unused [-Wunused-command-line-argument]
  clang++: warning: -Wl,--no-whole-archive: 'linker' input unused [-Wunused-command-line-argument]
  [2/4] Building CXX object CMakeFiles/native-lib.dir/home/sergey/projects/company_name/project_name/packages/project_name_ffi/cpp/native_project_name.cpp.o
  FAILED: CMakeFiles/native-lib.dir/home/sergey/projects/company_name/project_name/packages/project_name_ffi/cpp/native_project_name.cpp.o 
  /home/sergey/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --target=aarch64-none-linux-android23 --gcc-toolchain=/home/sergey/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64 --sysroot=/home/sergey/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot -Dnative_lib_EXPORTS -I../../../../../cpp/general -I../../../../src/main/opencv2/include -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security  -lGLESv2 -frtti -fexceptions -std=c++11 -Wl,--no-whole-archive -O2 -g -DNDEBUG -fPIC -MD -MT CMakeFiles/native-lib.dir/home/sergey/projects/company_name/project_name/packages/project_name_ffi/cpp/native_project_name.cpp.o -MF CMakeFiles/native-lib.dir/home/sergey/projects/company_name/project_name/packages/project_name_ffi/cpp/native_project_name.cpp.o.d -o CMakeFiles/native-lib.dir/home/sergey/projects/company_name/project_name/packages/project_name_ffi/cpp/native_project_name.cpp.o -c /home/sergey/projects/company_name/project_name/packages/project_name_ffi/cpp/native_project_name.cpp
  clang++: warning: -lGLESv2: 'linker' input unused [-Wunused-command-line-argument]
  clang++: warning: -Wl,--no-whole-archive: 'linker' input unused [-Wunused-command-line-argument]
  In file included from /home/sergey/projects/company_name/project_name/packages/project_name_ffi/cpp/native_project_name.cpp:2:
  In file included from ../../../../src/main/opencv2/include/opencv2/opencv.hpp:52:
  In file included from ../../../../src/main/opencv2/include/opencv2/core.hpp:53:
  In file included from ../../../../src/main/opencv2/include/opencv2/core/base.hpp:58:
  In file included from ../../../../src/main/opencv2/include/opencv2/core/cvstd.hpp:81:
  In file included from ../../../../src/main/opencv2/include/opencv2/core/cvstd_wrapper.hpp:11:
  /snap/flutter/current/usr/include/c++/8/memory:116:25: error: cast from pointer to smaller type 'uintptr_t' (aka 'unsigned int') loses information
    const auto __intptr = reinterpret_cast<uintptr_t>(__ptr);
                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

flutter doctor -v returns

[✓] Flutter (Channel stable, 3.0.2, on Linux Mint 20.3 5.4.0-117-generic, locale en_US.UTF-8)
    • Flutter version 3.0.2 at /home/sergey/snap/flutter/common/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision cd41fdd495 (8 days ago), 2022-06-08 09:52:13 -0700
    • Engine revision f15f824b57
    • Dart version 2.17.3
    • DevTools version 2.12.2

[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
    • Android SDK at /home/sergey/Android/Sdk
    • Platform android-32, build-tools 32.1.0-rc1
    • Java binary at:
      /home/sergey/.local/share/JetBrains/Toolbox/apps/AndroidStudio/ch-0/213.7172.25.2113.8684940/jre/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at google-chrome

[✓] Linux toolchain - develop for Linux desktop
    • clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)
    • cmake version 3.10.2
    • ninja version 1.8.2
    • pkg-config version 0.29.1

[✓] Android Studio (version 2021.3)
    • Android Studio at /home/sergey/.local/share/JetBrains/Toolbox/apps/AndroidStudio/ch-0/213.7172.25.2113.8684940
    • Flutter plugin version 68.1.3
    • Dart plugin version 213.7371
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)

[✓] VS Code
    • VS Code at /snap/code/current
    • Flutter extension can be installed from:
      🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (2 available)
    • Linux (desktop) • linux  • linux-x64      • Linux Mint 20.3 5.4.0-117-generic
    • Chrome (web)    • chrome • web-javascript • Google Chrome 102.0.5005.115

[✓] HTTP Host Availability
    • All required HTTP hosts are available
alexst07 commented 1 year ago

Same error here, it's been over a year and this issue has even been commented on, I imagine it won't be resolved by the developers.

kekland commented 12 months ago

Same is happening in https://github.com/kekland/croppy/issues/14.

We're using https://pub.dev/packages/ffigen to generate bindings automatically, if that's relevant.

The build logs are provided by @fortunado in the issue:

  In file included from /home/fortunado/.pub-cache/hosted/pub.dev/croppy-1.1.4/src/fit_polygon_in_quad.cpp:1:
  In file included from /home/fortunado/.pub-cache/hosted/pub.dev/croppy-1.1.4/src/kiwi/kiwi.h:9:
  In file included from /home/fortunado/.pub-cache/hosted/pub.dev/croppy-1.1.4/src/kiwi/constraint.h:12:
  In file included from /home/fortunado/.pub-cache/hosted/pub.dev/croppy-1.1.4/src/kiwi/expression.h:10:
  In file included from /home/fortunado/.pub-cache/hosted/pub.dev/croppy-1.1.4/src/kiwi/term.h:10:
  In file included from /home/fortunado/.pub-cache/hosted/pub.dev/croppy-1.1.4/src/kiwi/variable.h:9:
  /snap/flutter/current/usr/include/c++/9/memory:121:25: error: cast from pointer to smaller type 'uintptr_t' (aka 'unsigned int') loses information
    const auto __intptr = reinterpret_cast<uintptr_t>(__ptr);
                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

memory is included in the source code of kiwi: https://github.com/nucleic/kiwi/blob/main/kiwi/variable.h (line 9)

wang-bin commented 1 month ago

because CPLUS_INCLUDE_PATH is set to libc++ dirs in snap