4bb4 / implot-rs

Rust bindings to https://github.com/epezent/implot
Apache License 2.0
54 stars 22 forks source link

error: use of undeclared identifier 'isnan' on macOS Big Sur (11.4 and 11.5) #22

Open maoe opened 3 years ago

maoe commented 3 years ago

When cargo build in a clean checkout, I get:

% cargo build
   Compiling implot-sys v0.4.0 (/Users/maoe/src/github.com/4bb4/implot-rs/implot-sys)
The following warnings were emitted during compilation:

warning: In file included from third-party/cimplot/implot/implot.cpp:69:
warning: In file included from third-party/cimplot/implot/implot_internal.h:39:
warning: In file included from /Users/maoe/.cargo/registry/src/github.com-1ecc6299db9ec823/imgui-sys-0.6.0
/third-party/imgui/imgui_internal.h:48:
warning: In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Develo
per/SDKs/MacOSX.sdk/usr/include/c++/v1/math.h:309:
warning: In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Develo
per/SDKs/MacOSX.sdk/usr/include/c++/v1/type_traits:417:
warning: In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Develo
per/SDKs/MacOSX.sdk/usr/include/c++/v1/cstddef:37:
warning: /Users/maoe/.cargo/registry/src/github.com-1ecc6299db9ec823/imgui-sys-0.6.0/third-party/version:1
:1: error: unknown type name 'Generated'
warning: Generated by cimgui version 98e6ff7051df19b76854bc3eb3cea2798f8d3bc5
warning: ^
warning: /Users/maoe/.cargo/registry/src/github.com-1ecc6299db9ec823/imgui-sys-0.6.0/third-party/version:1
:13: error: expected ';' after top level declarator
warning: Generated by cimgui version 98e6ff7051df19b76854bc3eb3cea2798f8d3bc5
warning:             ^
warning: In file included from third-party/cimplot/implot/implot.cpp:69:
warning: third-party/cimplot/implot/implot_internal.h:101:84: error: use of undeclared identifier 'isnan'
warning: inline bool ImNanOrInf(double val) { return val == HUGE_VAL || val == -HUGE_VAL || isnan(val); }
warning:                                                                                    ^
warning: third-party/cimplot/implot/implot_internal.h:103:51: error: use of undeclared identifier 'isnan'
warning: inline double ImConstrainNan(double val) { return isnan(val) ? 0 : val; }
warning:                                                   ^
warning: 4 errors generated.

error: failed to run custom build command for `implot-sys v0.4.0 (/Users/maoe/src/github.com/4bb4/implot-r
s/implot-sys)`

Caused by:
  process didn't exit successfully: `/Users/maoe/src/github.com/4bb4/implot-rs/target/debug/build/implot-s
ys-3e514974c2ebd667/build-script-build` (exit status: 1)
  --- stdout
  TARGET = Some("x86_64-apple-darwin")
  OPT_LEVEL = Some("0")
  HOST = Some("x86_64-apple-darwin")
  CXX_x86_64-apple-darwin = None
  CXX_x86_64_apple_darwin = None
  HOST_CXX = None
  CXX = None
  CXXFLAGS_x86_64-apple-darwin = None
  CXXFLAGS_x86_64_apple_darwin = None
  HOST_CXXFLAGS = None
  CXXFLAGS = None
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("true")
  CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2,sse3,ssse3")
  CXX_x86_64-apple-darwin = None
  CXX_x86_64_apple_darwin = None
  HOST_CXX = None
  CXX = None
  CXXFLAGS_x86_64-apple-darwin = None
  CXXFLAGS_x86_64_apple_darwin = None
  HOST_CXXFLAGS = None
  CXXFLAGS = None
  CRATE_CC_NO_DEFAULTS = None
  CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2,sse3,ssse3")
  CXX_x86_64-apple-darwin = None
  CXX_x86_64_apple_darwin = None
  HOST_CXX = None
  CXX = None
  CXXFLAGS_x86_64-apple-darwin = None
  CXXFLAGS_x86_64_apple_darwin = None
  HOST_CXXFLAGS = None
  CXXFLAGS = None
  CRATE_CC_NO_DEFAULTS = None
  CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2,sse3,ssse3")
  CXX_x86_64-apple-darwin = None
  CXX_x86_64_apple_darwin = None
  HOST_CXX = None
  CXX = None
  CXXFLAGS_x86_64-apple-darwin = None
  CXXFLAGS_x86_64_apple_darwin = None
  HOST_CXXFLAGS = None
  CXXFLAGS = None
  CRATE_CC_NO_DEFAULTS = None
  CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2,sse3,ssse3")
  running: "c++" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m6
4" "-arch" "x86_64" "-I" "/Users/maoe/.cargo/registry/src/github.com-1ecc6299db9ec823/imgui-sys-0.6.0/thir
d-party" "-I" "/Users/maoe/.cargo/registry/src/github.com-1ecc6299db9ec823/imgui-sys-0.6.0/third-party/img
ui" "-I" "third-party/cimplot/implot/" "-Wall" "-Wextra" "-Wno-return-type-c-linkage" "-Wno-unused-paramet
er" "-std=c++11" "-DCIMGUI_NO_EXPORT" "-DIMGUI_DISABLE_OSX_FUNCTIONS" "-DIMGUI_DISABLE_WIN32_FUNCTIONS" "-
o" "/Users/maoe/src/github.com/4bb4/implot-rs/target/debug/build/implot-sys-3c5e13d3fc633769/out/third-par
ty/cimplot/cimplot.o" "-c" "third-party/cimplot/cimplot.cpp"
  exit status: 0
  running: "c++" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m6
4" "-arch" "x86_64" "-I" "/Users/maoe/.cargo/registry/src/github.com-1ecc6299db9ec823/imgui-sys-0.6.0/thir
d-party" "-I" "/Users/maoe/.cargo/registry/src/github.com-1ecc6299db9ec823/imgui-sys-0.6.0/third-party/img
ui" "-I" "third-party/cimplot/implot/" "-Wall" "-Wextra" "-Wno-return-type-c-linkage" "-Wno-unused-paramet
er" "-std=c++11" "-DCIMGUI_NO_EXPORT" "-DIMGUI_DISABLE_OSX_FUNCTIONS" "-DIMGUI_DISABLE_WIN32_FUNCTIONS" "-
o" "/Users/maoe/src/github.com/4bb4/implot-rs/target/debug/build/implot-sys-3c5e13d3fc633769/out/third-par
ty/cimplot/implot/implot.o" "-c" "third-party/cimplot/implot/implot.cpp"
  cargo:warning=In file included from third-party/cimplot/implot/implot.cpp:69:
  cargo:warning=In file included from third-party/cimplot/implot/implot_internal.h:39:
  cargo:warning=In file included from /Users/maoe/.cargo/registry/src/github.com-1ecc6299db9ec823/imgui-sy
s-0.6.0/third-party/imgui/imgui_internal.h:48:
  cargo:warning=In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform
/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/math.h:309:
  cargo:warning=In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform
/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/type_traits:417:
  cargo:warning=In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform
/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/cstddef:37:
  cargo:warning=/Users/maoe/.cargo/registry/src/github.com-1ecc6299db9ec823/imgui-sys-0.6.0/third-party/ve
rsion:1:1: error: unknown type name 'Generated'
  cargo:warning=Generated by cimgui version 98e6ff7051df19b76854bc3eb3cea2798f8d3bc5
  cargo:warning=^
  cargo:warning=/Users/maoe/.cargo/registry/src/github.com-1ecc6299db9ec823/imgui-sys-0.6.0/third-party/ve
rsion:1:13: error: expected ';' after top level declarator
  cargo:warning=Generated by cimgui version 98e6ff7051df19b76854bc3eb3cea2798f8d3bc5
  cargo:warning=            ^
  cargo:warning=In file included from third-party/cimplot/implot/implot.cpp:69:
  cargo:warning=third-party/cimplot/implot/implot_internal.h:101:84: error: use of undeclared identifier '
isnan'
  cargo:warning=inline bool ImNanOrInf(double val) { return val == HUGE_VAL || val == -HUGE_VAL || isnan(v
al); }
  cargo:warning=                                                                                   ^
  cargo:warning=third-party/cimplot/implot/implot_internal.h:103:51: error: use of undeclared identifier '
isnan'
  cargo:warning=inline double ImConstrainNan(double val) { return isnan(val) ? 0 : val; }
  cargo:warning=                                                  ^
  cargo:warning=4 errors generated.
  exit status: 1

  --- stderr

  error occurred: Command "c++" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-fram
e-pointer" "-m64" "-arch" "x86_64" "-I" "/Users/maoe/.cargo/registry/src/github.com-1ecc6299db9ec823/imgui
-sys-0.6.0/third-party" "-I" "/Users/maoe/.cargo/registry/src/github.com-1ecc6299db9ec823/imgui-sys-0.6.0/
third-party/imgui" "-I" "third-party/cimplot/implot/" "-Wall" "-Wextra" "-Wno-return-type-c-linkage" "-Wno
-unused-parameter" "-std=c++11" "-DCIMGUI_NO_EXPORT" "-DIMGUI_DISABLE_OSX_FUNCTIONS" "-DIMGUI_DISABLE_WIN3
2_FUNCTIONS" "-o" "/Users/maoe/src/github.com/4bb4/implot-rs/target/debug/build/implot-sys-3c5e13d3fc63376
9/out/third-party/cimplot/implot/implot.o" "-c" "third-party/cimplot/implot/implot.cpp" with args "c++" di
d not execute successfully (status code exit status: 1).

where

% c++ --version
Apple clang version 12.0.5 (clang-1205.0.22.11)
Target: x86_64-apple-darwin20.5.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

I'm on MacBook Pro 16'' 2019 (Intel). I'm sure it used to work but it stopped working at some point. Maybe when I upgraded the OS to Big Sur? I'm not sure.

maoe commented 3 years ago

Apparently it builds fine on Catalina: https://github.com/maoe/implot-rs/runs/2858954514. It's unfortunate that Big Sur CI runners aren't publicly available yet so we can't reproduce the issue in CI.

4bb4 commented 3 years ago

Interesting... I have access to a Mac, but I think it's still on Catalina as well. Looking at https://en.cppreference.com/w/cpp/numeric/math/isnan, it appears isnan should be defined in cmath / math.h, which in the linked version of implot_internal.h is included through imgui_internal.h here. So in principle the right headers should be included.

Looking around the internet for people with similar problems, I found https://stackoverflow.com/questions/68168291/macos-big-sur-m1-silicon-cmath-error-during-r-devtool-monocle3-install which is quite recent and where someone also had their math operations going missing on Big Sur. They solved their issue by including the math.h on their system by an absolute path - which of course is not a permanent solution and will not be portable, but it's something we could try out.

You could also try experimenting with building simple code that includes math.h and then uses something like isnan on your system:

#include <math.h>

int main(void) {
    double x = 0.0;
    bool is_it_nan = isnan(x);
}

If that already doesn't build with the clang on your system, maybe something with the system include paths is wrong. If it does, we need to look for why it works there but does not for the implot build.

maoe commented 3 years ago

Thanks for your input. The snippet builds fine with the clang on my system:

% cat isnan.cc
#include <math.h>
using namespace std;

int main(void) {
    double x = 0.0;
    bool is_it_nan = isnan(x);
}
% c++ -v isnan.cc
Apple clang version 12.0.5 (clang-1205.0.22.11)
Target: x86_64-apple-darwin20.5.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx11.0.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -Werror=implicit-function-declaration -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name isnan.cc -mrelocation-model pic -pic-level 2 -mframe-pointer=all -fno-strict-return -fno-rounding-math -munwind-tables -target-sdk-version=11.3 -fvisibility-inlines-hidden-static-local-var -target-cpu penryn -debugger-tuning=lldb -target-linker-version 650.9 -v -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.5 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -I/usr/local/include -stdlib=libc++ -internal-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1 -internal-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/local/include -internal-isystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.5/include -internal-externc-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include -internal-externc-isystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -Wno-reorder-init-list -Wno-implicit-int-float-conversion -Wno-c99-designator -Wno-final-dtor-non-final-class -Wno-extra-semi-stmt -Wno-misleading-indentation -Wno-quoted-include-in-framework-header -Wno-implicit-fallthrough -Wno-enum-enum-conversion -Wno-enum-float-conversion -Wno-elaborated-enum-base -fdeprecated-macro -fdebug-compilation-dir /tmp -ferror-limit 19 -stack-protector 1 -fstack-check -mdarwin-stkchk-strong-link -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -fmax-type-align=16 -fcommon -fcolor-diagnostics -clang-vendor-feature=+disableNonDependentMemberExprInCurrentInstantiation -fno-odr-hash-protocols -mllvm -disable-aligned-alloc-awareness=1 -o /var/folders/3t/ycv0ctpn4qb5k7djxy72k4dm0000gn/T/isnan-7ac428.o -x c++ isnan.cc
clang -cc1 version 12.0.5 (clang-1205.0.22.11) default target x86_64-apple-darwin20.5.0
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/local/include"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.5/include
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
End of search list.
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -lto_library /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libLTO.dylib -no_deduplicate -dynamic -arch x86_64 -platform_version macos 11.0.0 11.3 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -o a.out -L/usr/local/lib /var/folders/3t/ycv0ctpn4qb5k7djxy72k4dm0000gn/T/isnan-7ac428.o -lc++ -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.5/lib/darwin/libclang_rt.osx.a
% echo $?
0
4bb4 commented 3 years ago

Good, that means nothing is wrong with the system's include path in general. I'm upgrading to Big Sur now and will try out whether I can reproduce the problem then. I think I'm getting 11.5 in the upgrade, but it'll be a data point anyway.

maoe commented 3 years ago

FWIW I just updated macOS to 11.5 and confirmed that the issue remained.

4bb4 commented 3 years ago

Bad news first: The build worked fine on my machine also on Catalina, so I can't reproduce the problem. That doesn't mean it's not a problem of course, it just makes it trickier for me to help.

The good news is that I think I found what the problem is: I looked a bit more closely at your error output. The early part makes it seem as if it's trying to interpret the VERSION file as code. What's more, this seems to be the case at line 37 of /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform /Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/cstddef.

I went and looked at that line on my system, and it is:

#include <version>

.... I guess that shows where the issue comes from (to spell it out: It seems the build is attempting to include this spurious VERSION file I linked to instead of the C++ version header) . The reason I don't have that problem on my system is likely that I've configured my file system to have case-sensitive file names, but if I remember correctly, the default is to be case insensitive, which I suspect you have.

I have to think about how to best fix this - likely the build will start working for you if you locally delete /Users/maoe/.cargo/registry/src/github.com-1ecc6299db9ec823/imgui-sys-0.6.0/third-party/version and then do cargo build again (cargo does not notice if you delete files from its cache, since one would not typically do this... but for this experiment it would be worth a shot). I'll try to think of a more permanent solution and get back to you.

maoe commented 3 years ago

likely the build will start working for you if you locally delete /Users/maoe/.cargo/registry/src/github.com-1ecc6299db9ec823/imgui-sys-0.6.0/third-party/version and then do cargo build again

This indeed fixed the build issue, and yes, I'm using the case-insensitive filesystem. I'm meaning to migrate to case-sensitive file system though I haven't gotten around to it yet..

4bb4 commented 3 years ago

This has been found and fixed upstream in https://github.com/imgui-rs/imgui-rs/commit/794ece895673a94fe480e1d81587108f34c8f586 already a while back, but we have not yet been able to profit from that fix so far because of https://github.com/4bb4/implot-rs/issues/13. However, #13 is now un-blocked, so I expect to be able to soon merge https://github.com/4bb4/implot-rs/pull/24 and with that fix the issue here as well.

maoe commented 3 years ago

Nice! Thanks for the heads up.

4bb4 commented 3 years ago

Unfortunately this will take a little while longer, since I noticed that the latest release of imgui-rs we now point to (https://github.com/imgui-rs/imgui-rs/tree/v0.7.0) does not include the fix yet after all, sorry. I can point the imgui-rs dependency version to imgui-rs's master (which has the fix), but I can't make a release of that because crates.io does not take releases of packages that point to git dependencies. I'll ping you once I do that on master or a branch - it will take a bit of work because there are API changes on imgui-rs master as well.

maoe commented 3 years ago

Thanks for the heads up. It's okay. I've been using the workaround that you suggested earlier for now so it's not a showstopper.

4bb4 commented 2 years ago

@maoe the master branch now points to imgui 0.8, which should have the fix for the issue here. If you get around to trying this, let me know if it works for you so I can decide whether to close the issue here or more work is needed.

maoe commented 2 years ago

The master branch builds fine on macOS. Thanks!