taigw / GeodisTK

geodesic distance transform of 2d/3d images
MIT License
130 stars 35 forks source link

Build error on clang 13.0.1 #14

Closed jacobmerson closed 2 years ago

jacobmerson commented 2 years ago

When building with clang13.0.1 I get errors related to narrowing conversions see below.

Compiler info:

Homebrew clang version 13.0.1
Target: arm64-apple-darwin21.4.0
Thread model: posix
InstalledDir: /opt/homebrew/opt/llvm/bin
  Running setup.py install for GeodisTK ... error
  error: subprocess-exited-with-error

  × Running setup.py install for GeodisTK did not run successfully.
  │ exit code: 1
  ╰─> [79 lines of output]
      running install
      /Users/jacobmerson/geodis/lib/python3.9/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
        warnings.warn(
      running build
      running build_ext
      building 'GeodisTK' extension
      creating build
      creating build/temp.macosx-12-arm64-cpython-39
      creating build/temp.macosx-12-arm64-cpython-39/cpp
      clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk -I/Users/jacobmerson/geodis/lib/python3.9/site-packages/numpy/core/include -I./cpp -I/Users/jacobmerson/geodis/include -I/opt/homebrew/opt/python@3.9/Frameworks/Python.framework/Versions/3.9/include/python3.9 -c ./cpp/geodesic_distance.cpp -o build/temp.macosx-12-arm64-cpython-39/./cpp/geodesic_distance.o
      In file included from ./cpp/geodesic_distance.cpp:3:
      In file included from /Users/jacobmerson/geodis/lib/python3.9/site-packages/numpy/core/include/numpy/arrayobject.h:5:
      In file included from /Users/jacobmerson/geodis/lib/python3.9/site-packages/numpy/core/include/numpy/ndarrayobject.h:12:
      In file included from /Users/jacobmerson/geodis/lib/python3.9/site-packages/numpy/core/include/numpy/ndarraytypes.h:1948:
      /Users/jacobmerson/geodis/lib/python3.9/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: "Using deprecated NumPy API, disable it with "          "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-W#warnings]
      #warning "Using deprecated NumPy API, disable it with " \
       ^
      ./cpp/geodesic_distance.cpp:28:16: warning: unused variable 'shape_seed' [-Wunused-variable]
          npy_intp * shape_seed = PyArray_DIMS(arr_Seed);
                     ^
      ./cpp/geodesic_distance.cpp:76:16: warning: unused variable 'shape_seed' [-Wunused-variable]
          npy_intp * shape_seed = PyArray_DIMS(arr_Seed);
                     ^
      ./cpp/geodesic_distance.cpp:126:16: warning: unused variable 'shape_seed' [-Wunused-variable]
          npy_intp * shape_seed = PyArray_DIMS(arr_Seed);
                     ^
      ./cpp/geodesic_distance.cpp:185:16: warning: unused variable 'shape_seed' [-Wunused-variable]
          npy_intp * shape_seed = PyArray_DIMS(arr_Seed);
                     ^
      In file included from ./cpp/geodesic_distance.cpp:3:
      In file included from /Users/jacobmerson/geodis/lib/python3.9/site-packages/numpy/core/include/numpy/arrayobject.h:5:
      In file included from /Users/jacobmerson/geodis/lib/python3.9/site-packages/numpy/core/include/numpy/ndarrayobject.h:21:
      /Users/jacobmerson/geodis/lib/python3.9/site-packages/numpy/core/include/numpy/__multiarray_api.h:1477:1: warning: unused function '_import_array' [-Wunused-function]
      _import_array(void)
      ^
      ./cpp/geodesic_distance.cpp:222:20: warning: unused variable 'Methods' [-Wunused-variable]
      static PyMethodDef Methods[] = {
                         ^
      7 warnings generated.
      clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk -I/Users/jacobmerson/geodis/lib/python3.9/site-packages/numpy/core/include -I./cpp -I/Users/jacobmerson/geodis/include -I/opt/homebrew/opt/python@3.9/Frameworks/Python.framework/Versions/3.9/include/python3.9 -c ./cpp/geodesic_distance_2d.cpp -o build/temp.macosx-12-arm64-cpython-39/./cpp/geodesic_distance_2d.o
      ./cpp/geodesic_distance_2d.cpp:12:22: warning: comparison of integers of different signs: 'int' and 'std::vector<float>::size_type' (aka 'unsigned long') [-Wsign-compare]
          for(int d = 0; d < p1.size(); d++)
                         ~ ^ ~~~~~~~~~
      ./cpp/geodesic_distance_2d.cpp:23:35: warning: comparison of integers of different signs: 'int' and 'std::vector<Point2D>::size_type' (aka 'unsigned long') [-Wsign-compare]
          for(int i = start_position; i < list->size(); i++)
                                      ~ ^ ~~~~~~~~~~~~
      ./cpp/geodesic_distance_2d.cpp:37:22: warning: comparison of integers of different signs: 'int' and 'std::vector<Point2D>::size_type' (aka 'unsigned long') [-Wsign-compare]
          for(int i = 0; i < list->size(); i++)
                         ~ ^ ~~~~~~~~~~~~
      ./cpp/geodesic_distance_2d.cpp:175:33: error: non-constant-expression cannot be narrowed from type 'double' to 'float' in initializer list [-Wc++11-narrowing]
              float local_dis_f[4] = {sqrt(2.0), 1.0, sqrt(2.0), 1.0};
                                      ^~~~~~~~~
      ./cpp/geodesic_distance_2d.cpp:175:33: note: insert an explicit cast to silence this issue
              float local_dis_f[4] = {sqrt(2.0), 1.0, sqrt(2.0), 1.0};
                                      ^~~~~~~~~
                                      static_cast<float>( )
      ./cpp/geodesic_distance_2d.cpp:175:49: error: non-constant-expression cannot be narrowed from type 'double' to 'float' in initializer list [-Wc++11-narrowing]
              float local_dis_f[4] = {sqrt(2.0), 1.0, sqrt(2.0), 1.0};
                                                      ^~~~~~~~~
      ./cpp/geodesic_distance_2d.cpp:175:49: note: insert an explicit cast to silence this issue
              float local_dis_f[4] = {sqrt(2.0), 1.0, sqrt(2.0), 1.0};
                                                      ^~~~~~~~~
                                                      static_cast<float>( )
      ./cpp/geodesic_distance_2d.cpp:203:38: error: non-constant-expression cannot be narrowed from type 'double' to 'float' in initializer list [-Wc++11-narrowing]
              float local_dis_b[4] = {1.0, sqrt(2.0), 1.0, sqrt(2.0)};
                                           ^~~~~~~~~
      ./cpp/geodesic_distance_2d.cpp:203:38: note: insert an explicit cast to silence this issue
              float local_dis_b[4] = {1.0, sqrt(2.0), 1.0, sqrt(2.0)};
                                           ^~~~~~~~~
                                           static_cast<float>( )
      ./cpp/geodesic_distance_2d.cpp:203:54: error: non-constant-expression cannot be narrowed from type 'double' to 'float' in initializer list [-Wc++11-narrowing]
              float local_dis_b[4] = {1.0, sqrt(2.0), 1.0, sqrt(2.0)};
                                                           ^~~~~~~~~
      ./cpp/geodesic_distance_2d.cpp:203:54: note: insert an explicit cast to silence this issue
              float local_dis_b[4] = {1.0, sqrt(2.0), 1.0, sqrt(2.0)};
                                                           ^~~~~~~~~
                                                           static_cast<float>( )
      3 warnings and 4 errors generated.
      error: command '/opt/homebrew/opt/llvm/bin/clang' failed with exit code 1
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure

× Encountered error while trying to install package.
╰─> GeodisTK
jacobmerson commented 2 years ago

The errors can be fixed by replacing the calls of sqrt to sqrtf or as the compiler suggests you can do an explicit static_cast to float.

taigw commented 2 years ago

Thanks @jacobmerson for you contribution!