berthubert / hello-dl

https://berthub.eu/tmp/hello-dl
MIT License
71 stars 9 forks source link

feenableexcept undefined when building on macOS #4

Open hwschuur opened 1 year ago

hwschuur commented 1 year ago

Output from building on macOS:

[  2%] Building CXX object CMakeFiles/common.dir/mnistreader.cc.o
[  4%] Building CXX object CMakeFiles/common.dir/textsupport.cc.o
clang: clang: warning: argument unused during compilation: '-msse2' [-Wunused-command-line-argument]warning:
clang: warning: argument unused during compilation: '-mavx' [-Wunused-command-line-argument]
argument unused during compilation: '-msse2' [-Wunused-command-line-argument]
clang: clangwarning: : warning: argument unused during compilation: '-mavx' [-Wunused-command-line-argument]
argument unused during compilation: '-mavx2' [-Wunused-command-line-argument]clang:
clangwarning: : argument unused during compilation: '-mavx2' [-Wunused-command-line-argument]warning:
clang: warning: argument unused during compilation: '-mfma' [-Wunused-command-line-argument]
argument unused during compilation: '-mfma' [-Wunused-command-line-argument]
[  4%] Built target common
[ 14%] Building CXX object CMakeFiles/tensor-convo.dir/tensor-convo.cc.o
[ 14%] Building CXX object CMakeFiles/img-ocr.dir/img-ocr.cc.o
[ 14%] Building CXX object CMakeFiles/tensor-convo-par.dir/tensor-convo-par.cc.o
[ 14%] Building CXX object CMakeFiles/tensor-relu.dir/tensor-relu.cc.o
clang: warning: argument unused during compilation: '-msse2' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-mavx' [-Wunused-command-line-argument]
clang: clang: warning: argument unused during compilation: '-msse2' [-Wunused-command-line-argument]
clangwarning: : warning: argument unused during compilation: '-mavx' [-Wunused-command-line-argument]
argument unused during compilation: '-mavx2' [-Wunused-command-line-argument]
clang: clang: clangwarning: warning: : warning: argument unused during compilation: '-mfma' [-Wunused-command-line-argument]argument unused during compilation: '-msse2' [-Wunused-command-line-argument]

clang: argument unused during compilation: '-mavx2' [-Wunused-command-line-argument]warning:
argument unused during compilation: '-msse2' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-mavx' [-Wunused-command-line-argument]
clang: warning: clang: argument unused during compilation: '-mavx2' [-Wunused-command-line-argument]warning:
argument unused during compilation: '-mfma' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-mavx' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-mavx2' [-Wunused-command-line-argument]
clang: warning: clang: warning: argument unused during compilation: '-mfma' [-Wunused-command-line-argument]
argument unused during compilation: '-mfma' [-Wunused-command-line-argument]
/Users/hvanderschuur/Projects/dev/hello-dl/img-ocr.cc:39:27: warning: lambda capture 'rows' is not used [-Wunused-lambda-capture]
  auto getintens=[&data, &rows, &cols](int c, int r) {
                       ~~~^~~~
/Users/hvanderschuur/Projects/dev/hello-dl/tensor-relu.cc:90:3: error: use of undeclared identifier 'feenableexcept'; did you mean 'feraiseexcept'?
  feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW );
  ^~~~~~~~~~~~~~
  feraiseexcept
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/usr/include/fenv.h:299:12: note: 'feraiseexcept' declared here
extern int feraiseexcept(int /* excepts */);
           ^
/Users/hvanderschuur/Projects/dev/hello-dl/tensor-convo.cc:67:3: error: use of undeclared identifier 'feenableexcept'; did you mean 'feraiseexcept'?
  feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW );
  ^~~~~~~~~~~~~~
  feraiseexcept
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/usr/include/fenv.h:299:12: note: 'feraiseexcept' declared here
extern int feraiseexcept(int /* excepts */);
           ^
1 error generated.
make[2]: *** [CMakeFiles/tensor-relu.dir/tensor-relu.cc.o] Error 1
make[1]: *** [CMakeFiles/tensor-relu.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
1 error generated.
make[2]: *** [CMakeFiles/tensor-convo.dir/tensor-convo.cc.o] Error 1
make[1]: *** [CMakeFiles/tensor-convo.dir/all] Error 2
[ 17%] Building CXX object CMakeFiles/tensor-convo-par.dir/ext/sqlitewriter/sqlwriter.cc.o
clang: warning: argument unused during compilation: '-msse2' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-mavx' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-mavx2' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-mfma' [-Wunused-command-line-argument]
[ 19%] Building CXX object CMakeFiles/img-ocr.dir/vizi.cc.o
clang: warning: argument unused during compilation: '-msse2' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-mavx' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-mavx2' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-mfma' [-Wunused-command-line-argument]
In file included from /Users/hvanderschuur/Projects/dev/hello-dl/vizi.cc:7:
/Users/hvanderschuur/Projects/dev/hello-dl/ext/stb/stb_image_write.h:776:13: warning: 'sprintf' is deprecated: This function is provided for compatibility reasons only.  Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead. [-Wdeprecated-declarations]
      len = sprintf(buffer, "EXPOSURE=          1.0000000000000\n\n-Y %d +X %d\n", y, x);
            ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/usr/include/stdio.h:188:1: note: 'sprintf' has been explicitly marked deprecated here
__deprecated_msg("This function is provided for compatibility reasons only.  Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead.")
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/usr/include/sys/cdefs.h:215:48: note: expanded from macro '__deprecated_msg'
        #define __deprecated_msg(_msg) __attribute__((__deprecated__(_msg)))
                                                      ^
/Users/hvanderschuur/Projects/dev/hello-dl/vizi.cc:66:22: warning: lambda capture 'out' is not used [-Wunused-lambda-capture]
  auto box = [&pix, &out](int col, int row, int w, int h, uint8_t cr, uint8_t cg, uint8_t cb) {
                  ~~~^~~
1 warning generated.
2 warnings generated.
[ 21%] Linking CXX executable img-ocr
[ 21%] Built target img-ocr
[ 24%] Linking CXX executable tensor-convo-par
[ 24%] Built target tensor-convo-par
make: *** [all] Error 2

Found some articles that seem to provide a solution… unfortunately, I lack the skills to apply it :-)

fortiko commented 1 year ago

@hwschuur hello, simply wrap this and the other occurrences in #ifndef __APPLE__ and #endif respectively before and after the offending line, like so (example taken from tensor-convo.cc):

#ifndef __APPLE__
  feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW );
#endif

Be careful, the line that contains feenableexcept might be different in each file, so add the #ifndef __APPLE__ and #endif combo by hand, don't copy/paste the whole block with 3 lines!

fortiko commented 1 year ago

Files that need to be adapted:

first-convo.cc:  feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW );
mnistposter.cc:  feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW );
tensor-convo.cc:  feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW );
tensor-relu.cc:  feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW );
try-convo.cc:  feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW );

Note that tensor-convo-par.cc also contains the line, but it is commented out and thefore can be left as is:

// feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW );