Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include missing <math.h> #1431

Merged
merged 7 commits into from
Jun 19, 2024
Merged

Include missing <math.h> #1431

merged 7 commits into from
Jun 19, 2024

Conversation

luncliff
Copy link
Contributor

Hi, team. I'm trying https://snapcraft.io/ packaging of vcpkg-tool with public vcpkg registries.
https://github.com/luncliff/vcpkg-tool-snapcraft/blob/main/snap/snapcraft.yaml

While doing the work, I met the following errors in the Snapcraft build.
(Full Log - https://github.com/luncliff/vcpkg-tool-snapcraft/actions/runs/9353571615)

Environment

In the Snapcraft build, I used the Ubuntu 22.04 environment.

# ...
base: core22

parts:
  vcpkg:
    plugin: cmake
    source: https://github.com/microsoft/vcpkg-tool.git
    source-tag: "2024-04-23"
    source-type: git
    source-depth: 1
    cmake-generator: Ninja
    cmake-parameters:
      - -DCMAKE_INSTALL_PREFIX=/usr/local
      - -DBUILD_TESTING=OFF
      - -DVCPKG_DEVELOPMENT_WARNINGS=OFF
      - -DVCPKG_EMBED_GIT_SHA=ON
      - -DVCPKG_DEPENDENCY_EXTERNAL_FMT=OFF
      - -DFMT_INSTALL=OFF
    build-packages: # for build
      - git
      # - clang-15
      # - libc++-15-dev
    stage-packages: # for runtime
      - git
      - gcc
      - g++
      # - clang-15
      # - libc++-15-dev
      - curl
      - zip
      - unzip
      - tar

With Clang 15

Here, isfinite in metrics.cpp causes compiler error with Clang 15

2024-06-03T16:14:54.3908197Z :: + cmake /root/parts/vcpkg/src -G Ninja -DCMAKE_INSTALL_PREFIX=/usr/local -DCMAKE_C_COMPILER=clang-15 -DCMAKE_CXX_COMPILER=clang++-15 -DBUILD_TESTING=OFF -DVCPKG_DEVELOPMENT_WARNINGS=OFF -DVCPKG_EMBED_GIT_SHA=ON -DVCPKG_DEPENDENCY_EXTERNAL_FMT=OFF -DFMT_INSTALL=OFF
2024-06-03T16:14:54.4747537Z :: -- The C compiler identification is Clang 15.0.7
2024-06-03T16:14:54.5509178Z :: -- The CXX compiler identification is Clang 15.0.7
...
2024-06-03T16:14:56.7162497Z :: -- Build files have been written to: /root/parts/vcpkg/build
2024-06-03T16:14:56.7210809Z :: + cmake --build . -- -j4
2024-06-03T16:14:56.7331818Z :: [0/2] Re-checking globbed directories...
2024-06-03T16:14:56.7561178Z :: [1/150] Generating locale-resources resource loader
...
2024-06-03T16:14:57.4854271Z :: [13/150] Generating vcpkg.ps1
...
2024-06-03T16:15:23.2999860Z :: [128/150] Building CXX object CMakeFiles/vcpkglib.dir/src/vcpkg/metrics.cpp.o
2024-06-03T16:15:23.3003590Z :: FAILED: CMakeFiles/vcpkglib.dir/src/vcpkg/metrics.cpp.o
2024-06-03T16:15:23.3011872Z :: /root/parts/vcpkg/install/usr/bin/clang++-15 -DVCPKG_BASE_VERSION=2999-12-31 -DVCPKG_VERSION=4697044ee78033dcb38c68b536b0c96a07e887c1 -D_FILE_OFFSET_BITS=64 -I/root/parts/vcpkg/src/include -I/root/parts/vcpkg/build/_deps/fmt-src/include -I/root/parts/vcpkg/build/_cmrc/include -isystem /root/parts/vcpkg/install/usr/include -isystem /root/parts/vcpkg/install/usr/include/x86_64-linux-gnu -std=c++17 -Winvalid-pch -Xclang -include-pch -Xclang /root/parts/vcpkg/build/CMakeFiles/vcpkglib.dir/cmake_pch.hxx.pch -Xclang -include -Xclang /root/parts/vcpkg/build/CMakeFiles/vcpkglib.dir/cmake_pch.hxx -MD -MT CMakeFiles/vcpkglib.dir/src/vcpkg/metrics.cpp.o -MF CMakeFiles/vcpkglib.dir/src/vcpkg/metrics.cpp.o.d -o CMakeFiles/vcpkglib.dir/src/vcpkg/metrics.cpp.o -c /root/parts/vcpkg/src/src/vcpkg/metrics.cpp
2024-06-03T16:15:23.3016838Z :: /root/parts/vcpkg/src/src/vcpkg/metrics.cpp:164:14: error: use of undeclared identifier 'isfinite'; did you mean 'std::isfinite'?
2024-06-03T16:15:23.3017839Z ::         if (!isfinite(value) || value <= 0.0)
2024-06-03T16:15:23.3018283Z ::              ^~~~~~~~
2024-06-03T16:15:23.3021792Z ::              std::isfinite
2024-06-03T16:15:23.3026639Z :: /root/parts/vcpkg/install/usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/cmath:566:3: note: 'std::isfinite' declared here
2024-06-03T16:15:23.3029934Z ::   isfinite(double __x)
2024-06-03T16:15:23.3033911Z ::   ^
2024-06-03T16:15:23.3037937Z :: 1 error generated.
...
2024-06-03T16:15:24.0812788Z Failed to run the build script for part 'vcpkg'.

With GCC 11.2

When tried with default cc and c++, json.cpp compilation fails with similar error.
(Full Log - https://github.com/luncliff/vcpkg-tool-snapcraft/actions/runs/9353303217/job/25743474181)

2024-06-03T15:58:50.0719607Z :: + cmake /root/parts/vcpkg/src -G Ninja -DCMAKE_INSTALL_PREFIX=/usr/local -DBUILD_TESTING=OFF -DVCPKG_DEVELOPMENT_WARNINGS=OFF -DVCPKG_EMBED_GIT_SHA=ON -DVCPKG_DEPENDENCY_EXTERNAL_FMT=OFF -DFMT_INSTALL=OFF
2024-06-03T15:58:50.1273110Z :: -- The C compiler identification is GNU 11.2.0
2024-06-03T15:58:50.2852487Z :: -- The CXX compiler identification is GNU 11.2.0
...
2024-06-03T15:58:59.4330452Z :: [45/150] Building CXX object CMakeFiles/vcpkglib.dir/src/vcpkg/base/hash.cpp.o
2024-06-03T15:58:59.6990233Z :: [46/150] Building CXX object CMakeFiles/vcpkglib.dir/src/vcpkg/base/json.cpp.o
2024-06-03T15:58:59.6999065Z :: FAILED: CMakeFiles/vcpkglib.dir/src/vcpkg/base/json.cpp.o
2024-06-03T15:58:59.7010777Z :: /usr/bin/c++ -DVCPKG_BASE_VERSION=2999-12-31 -DVCPKG_VERSION=d6945642ee5c3076addd1a42c331bbf4cfc97457 -D_FILE_OFFSET_BITS=64 -I/root/parts/vcpkg/src/include -I/root/parts/vcpkg/build/_deps/fmt-src/include -I/root/parts/vcpkg/build/_cmrc/include -isystem /root/parts/vcpkg/install/usr/include -isystem /root/parts/vcpkg/install/usr/include/x86_64-linux-gnu -std=c++17 -Winvalid-pch -include /root/parts/vcpkg/build/CMakeFiles/vcpkglib.dir/cmake_pch.hxx -MD -MT CMakeFiles/vcpkglib.dir/src/vcpkg/base/json.cpp.o -MF CMakeFiles/vcpkglib.dir/src/vcpkg/base/json.cpp.o.d -o CMakeFiles/vcpkglib.dir/src/vcpkg/base/json.cpp.o -c /root/parts/vcpkg/src/src/vcpkg/base/json.cpp
2024-06-03T15:58:59.7023113Z :: /root/parts/vcpkg/src/src/vcpkg/base/json.cpp: In static member function ‘static vcpkg::Json::Value vcpkg::Json::Value::number(double)’:
2024-06-03T15:58:59.7031744Z :: /root/parts/vcpkg/src/src/vcpkg/base/json.cpp:259:52: error: ‘isfinite’ was not declared in this scope; did you mean ‘std::isfinite’?
2024-06-03T15:58:59.7039173Z ::   259 |         vcpkg::Checks::check_exit(VCPKG_LINE_INFO, isfinite(d));
2024-06-03T15:58:59.7046548Z ::       |                                                    ^~~~~~~~
2024-06-03T15:58:59.7053550Z ::       |                                                    std::isfinite
2024-06-03T15:58:59.7060832Z :: In file included from /root/parts/vcpkg/build/_deps/fmt-src/include/fmt/format.h:36,
2024-06-03T15:58:59.7067899Z ::                  from /root/parts/vcpkg/src/include/vcpkg/base/fmt.h:14,
2024-06-03T15:58:59.7074839Z ::                  from /root/parts/vcpkg/src/include/pch.h:5,
2024-06-03T15:58:59.7081805Z ::                  from /root/parts/vcpkg/build/CMakeFiles/vcpkglib.dir/cmake_pch.hxx:5,
2024-06-03T15:58:59.7088559Z ::                  from <command-line>:
2024-06-03T15:58:59.7095631Z :: /usr/include/c++/11/cmath:578:5: note: ‘std::isfinite’ declared here
2024-06-03T15:58:59.7102513Z ::   578 |     isfinite(_Tp __x)
2024-06-03T15:58:59.7109240Z ::       |     ^~~~~~~~
2024-06-03T15:58:59.7414151Z :: [47/150] Building CXX object CMakeFiles/vcpkglib.dir/src/vcpkg/base/message_sinks.cpp.o

Suggestion

Can we change those parts to use std::isfinite like the changes below?

@BillyONeal
Copy link
Member

BillyONeal commented Jun 14, 2024

Can we just add the missing #include <math.h>? At the moment we use the non-std:: forms everywhere else.

@luncliff
Copy link
Contributor Author

Change to <math.h> in e1c2bf3

src/vcpkg/base/json.cpp Outdated Show resolved Hide resolved
@BillyONeal
Copy link
Member

Format failures fixed in #1433

@BillyONeal BillyONeal enabled auto-merge (squash) June 19, 2024 00:25
@BillyONeal BillyONeal disabled auto-merge June 19, 2024 00:25
@BillyONeal BillyONeal enabled auto-merge (squash) June 19, 2024 00:26
@BillyONeal BillyONeal changed the title Replace isfinite to std::isfinite Include missing <math.h> Jun 19, 2024
@BillyONeal BillyONeal merged commit e6bf0cc into microsoft:main Jun 19, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants