简体   繁体   中英

Support for long long operations in C++ standard math library? (Apple silicon, macOS 11.3)

I've been beating my head against a wall for the past week trying to get a project to compile on my M1 Mac Mini (macOS Big Sur 11.4). Posting here rather than as an issue on the project Github page because this seems like a general toolchain issue. (Side note, I was able to compile the same code without any issues on my Win10 machine under WSL2 with a Debian-based distro and all the dependencies installed via apt-get)

Error (one of many, but all related to the long long variation of functions):

In file included from include/trick/Clock.hh:11:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX11.3.sdk/usr/include/c++/v1/string:506:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX11.3.sdk/usr/include/c++/v1/string_view:175:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX11.3.sdk/usr/include/c++/v1/__string:57:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX11.3.sdk/usr/include/c++/v1/algorithm:643:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX11.3.sdk/usr/include/c++/v1/memory:668:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX11.3.sdk/usr/include/c++/v1/typeinfo:60:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX11.3.sdk/usr/include/c++/v1/exception:81:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX11.3.sdk/usr/include/c++/v1/cstdlib:85:
/Library/Developer/CommandLineTools/SDKs/MacOSX11.3.sdk/usr/include/c++/v1/stdlib.h:148:12: error: no member named 'lldiv' in the global namespace; did you mean 'ldiv'?
  return ::lldiv(__x, __y);

I've tried following the advice from some comments in this thread but none have helped.

  • Installed XCode.app, changed the SDK path, and removed the CLT directory (I've since reverted to only having the CLT installed)
  • Added set(CMAKE_OSX_SYSROOT /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk) to the project's CMakeLists.txt
  • Explicitly setting clang, gcc, g++, etc... as the compiler in the ./configure flags
  • Explicitly including -I/path/to/MacOSX.sdk/usr/include in the CXXFLAGS set in ./configure
eric@Mac-Wahlberg ~ 
╰─$ clang -v                                                                                    1 ↵
Apple clang version 12.0.5 (clang-1205.0.22.11)
Target: arm64-apple-darwin20.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

╭─eric@Mac-Wahlberg ~ 
╰─$ gcc -v
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 12.0.5 (clang-1205.0.22.11)
Target: arm64-apple-darwin20.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

╭─eric@Mac-Wahlberg ~ 
╰─$ g++ -v
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 12.0.5 (clang-1205.0.22.11)
Target: arm64-apple-darwin20.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

╭─eric@Mac-Wahlberg ~ 
╰─$ xcrun --sdk macosx --show-sdk-path
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk

eric@Mac-Wahlberg ~/Code/trick ‹15534f7› 
╰─$ gcc -Wp,-v -E -
clang -cc1 version 12.0.5 (clang-1205.0.22.11) default target arm64-apple-darwin20.5.0
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/local/include"
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /Library/Developer/CommandLineTools/usr/lib/clang/12.0.5/include
 /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
 /Library/Developer/CommandLineTools/usr/include
 /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
End of search list.

Some more terminal copypasta that may or may not be useful

╭─eric@Mac-Wahlberg ~/Code/trick ‹15534f7*› 
╰─$ cat /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/C++/v1/stdlib.h | grep "lldiv"
    lldiv_t                                                               // C99
lldiv_t   div(long long numer, long long denom);                          // C++0X
lldiv_t lldiv(long long numer, long long denom);                          // C99
#undef lldiv
inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x,
  return ::lldiv(__x, __y);

The error says "There is no lldiv in the global namespace", it's not required to be there, std::lldiv is supposed to be there on conforming hosted implementations from C++11. Try compiling with -std=c++20 I don't have a problem on macOS 11 (can't speak for macOS 12)

Edit: Ignore the message above, it's only nitpicking.

Make sure you compile with -std=c++11 or above. eg:

cd ~/Desktop;\
echo '#include <cmath>\nint main(){}' > main.cxx;\
xcrun -r clang++ -std=c++11 main.cxx -o Main;\
./Main && printf '%s\n' Success.

That should print 'Success.'

If not run this:

xcode-select -p

That prints the path to the Developer folder. If it's not: /Applications/Xcode.app/Contents/Developer

First run this

xcode-select --install

IF it doesn't say: xcode-select: error: command line tools are already installed, use "Software Update" to install updates stop where you are and update/install Xcode from the Mac App Store

Otherwise:

sudo xcode-select --reset && xcode-select -p

It should print /Applications/Xcode.app/Contents/Developer

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM