How to enable C++11 on Mac

Dear LAMMPS Users,

I’m trying to install the latest stable version of LAMMPS (lammps-29Oct20) on my MacBook with macOS 11. When I use “make serial” command to compile, it shows me these:

make serial
make[1]: libmpi_stubs.a' is up to date. Gathering installed package information (may take a little while) make[1]: lmpinstalledpkgs.h’ is up to date.
Gathering git version information
Compiling LAMMPS for machine serial
g++ -g -O3 -DLAMMPS_GZIP -DLAMMPS_MEMALIGN=64 -I…/STUBS -c …/main.cpp
In file included from …/main.cpp:15:
In file included from …/input.h:17:
In file included from …/pointers.h:24:
…/lmptype.h:34:2: error: LAMMPS requires a C++11 (or later) compliant compiler. Enable C++11 compatibility or upgrade the compiler.
#error LAMMPS requires a C++11 (or later) compliant compiler. Enable C++11 compatibility or upgrade the compiler.
^
In file included from …/main.cpp:15:
In file included from …/input.h:17:
In file included from …/pointers.h:31:
In file included from …/fmt/format.h:44:
…/fmt/core.h:256:21: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using enable_if_t = typename std::enable_if<B, T>::type;
^
…/fmt/core.h:258:23: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using conditional_t = typename std::conditional<B, T, F>::type;
^
…/fmt/core.h:259:41: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
template using bool_constant = std::integral_constant<bool, B>;
^
…/fmt/core.h:261:28: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using remove_reference_t = typename std::remove_reference::type;
^
…/fmt/core.h:263:24: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using remove_const_t = typename std::remove_const::type;
^
…/fmt/core.h:265:24: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using remove_cvref_t = typename std::remove_cv<remove_reference_t>::type;
^
…/fmt/core.h:265:68: error: a space is required between consecutive right angle brackets (use ‘> >’)
using remove_cvref_t = typename std::remove_cv<remove_reference_t>::type;
^~
> >
…/fmt/core.h:266:59: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
template struct type_identity { using type = T; };
^
…/fmt/core.h:267:47: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
template using type_identity_t = typename type_identity::type;
^
…/fmt/core.h:280:23: error: unknown type name ‘constexpr’
template constexpr T const_check(T value) { return value; }
^
…/fmt/core.h:280:33: warning: variable templates are a C++14 extension [-Wc++14-extensions]
template constexpr T const_check(T value) { return value; }
^
…/fmt/core.h:280:34: error: expected ‘;’ at end of declaration
template constexpr T const_check(T value) { return value; }
^
;
…/fmt/core.h:280:47: error: unknown type name ‘T’
template constexpr T const_check(T value) { return value; }
^
…/fmt/core.h:280:35: error: C++ requires a type specifier for all declarations
template constexpr T const_check(T value) { return value; }
^
…/fmt/core.h:298:50: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
template using std_string_view = std::basic_string_view;
^
…/fmt/core.h:310:18: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using int128_t = int128_t;
^
…/fmt/core.h:311:19: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using uint128_t = uint128_t;
^
…/fmt/core.h:323:3: error: no member named ‘detail’ in namespace ‘fmt’; did you mean simply ‘detail’?
FMT_ASSERT(value >= 0, “negative value”);
^
…/fmt/core.h:293:14: note: expanded from macro ‘FMT_ASSERT’
: ::fmt::detail::assert_fail(FILE, LINE, (message)))
^
…/fmt/core.h:276:11: note: ‘detail’ declared here
namespace detail {
^
…/fmt/core.h:327:32: error: unknown type name ‘constexpr’
FMT_SUPPRESS_MSC_WARNING(4566) constexpr unsigned char micro[] = “\u00B5”;
^
…/fmt/core.h:329:26: error: unknown type name ‘constexpr’
template constexpr bool is_unicode() {
^
…/fmt/core.h:358:22: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using value_type = Char;
^
…/fmt/core.h:359:20: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using iterator = const Char*;
^
…/fmt/core.h:361:3: error: unknown type name ‘constexpr’
constexpr basic_string_view() FMT_NOEXCEPT : data
(nullptr), size
(0) {}
^
…/fmt/core.h:361:13: error: constructor cannot have a return type
constexpr basic_string_view() FMT_NOEXCEPT : data
(nullptr), size
(0) {}
^~~~~~~~~~~~~~~~~
…/fmt/core.h:364:3: error: unknown type name ‘constexpr’
constexpr basic_string_view(const Char* s, size_t count) FMT_NOEXCEPT
^
…/fmt/core.h:364:13: error: constructor cannot have a return type
constexpr basic_string_view(const Char* s, size_t count) FMT_NOEXCEPT
^~~~~~~~~~~~~~~~~
…/fmt/core.h:388:70: error: a space is required between consecutive right angle brackets (use ‘> >’)
S, detail::std_string_view>::value)>
^~
> >
…/fmt/core.h:274:41: note: expanded from macro ‘FMT_ENABLE_IF’
#define FMT_ENABLE_IF(…) enable_if_t<(VA_ARGS), int> = 0
^
…/fmt/core.h:387:25: warning: default template arguments for a function template are a C++11 extension [-Wc++11-extensions]
template <typename S, FMT_ENABLE_IF(std::is_same<
^~~~~~~~~~~~~~~~~~~~~~~~~~~
…/fmt/core.h:274:60: note: expanded from macro ‘FMT_ENABLE_IF’
#define FMT_ENABLE_IF(…) enable_if_t<(VA_ARGS), int> = 0
^ ~
…/fmt/core.h:393:3: error: unknown type name ‘constexpr’
constexpr const Char* data() const { return data_; }
^
…/fmt/core.h:393:19: error: declaration of ‘Char’ shadows template parameter
constexpr const Char* data() const { return data_; }
^
…/fmt/core.h:352:20: note: template parameter is declared here
template class basic_string_view {
^
…/fmt/core.h:393:23: error: expected ‘;’ at end of declaration list
constexpr const Char* data() const { return data_; }
^
;
…/fmt/core.h:437:21: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using string_view = basic_string_view;
^
…/fmt/core.h:438:22: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using wstring_view = basic_string_view<wchar_t>;
^
…/fmt/core.h:464:26: warning: default template arguments for a function template are a C++11 extension [-Wc++11-extensions]
template <typename Char, FMT_ENABLE_IF(is_char::value)>
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
…/fmt/core.h:274:60: note: expanded from macro ‘FMT_ENABLE_IF’
#define FMT_ENABLE_IF(…) enable_if_t<(VA_ARGS), int> = 0
^ ~
…/fmt/core.h:481:68: error: a space is required between consecutive right angle brackets (use ‘> >’)
FMT_ENABLE_IF(!std::is_empty<detail::std_string_view>::value)>
^~
> >
…/fmt/core.h:274:41: note: expanded from macro ‘FMT_ENABLE_IF’
#define FMT_ENABLE_IF(…) enable_if_t<(VA_ARGS), int> = 0
^
…/fmt/core.h:481:11: warning: default template arguments for a function template are a C++11 extension [-Wc++11-extensions]
FMT_ENABLE_IF(!std::is_empty<detail::std_string_view>::value)>
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
…/fmt/core.h:274:60: note: expanded from macro ‘FMT_ENABLE_IF’
#define FMT_ENABLE_IF(…) enable_if_t<(VA_ARGS), int> = 0
^ ~
…/fmt/core.h:494:1: error: unknown type name ‘constexpr’
constexpr basic_string_view to_string_view(const S& s) {
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
19 warnings and 20 errors generated.
make[1]: *** [main.o] Error 1
make: *** [serial] Error 2

It seems that the lammps-29Oct20 installation requires the C++11 standard compatible compiler, but I have no idea on how to fix it. Can anyone help me with it?

Thank you,
Steven

https://docs.lammps.org/Build_make.html#requirements

1 Like

Thanks for your reply!

Yes, I know it requires C++11 and I need to enable it from the error, but I don’t know how to add that flag and where to add it. I tried to search the internet but I still cannot fix it. Sorry I’m not familiar with this issue.

Steven

Oh, does that mean I need to add the flag ‘-std=c++11’ to somewhere in the Makefile in lammps/src ?

Steven

I tried to use Homebrew to install LAMMPS on Mac, it seems Homebrew can automatically help me install everything I need and I don’t need to enable C++11 by myself. Thanks.

Steven