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
c++11 compile error in Mac OS X #302
Comments
Hi @firatyenidunya, in order to use NanoGUI, you need more than just a c++11 capable compiler -- you have to compile with c++11 (or higher).
It goes the other way, you have to tell CMake which standard to use. The most platform-agnostic way to do this is at the beginning: cmake_minimum_required(VERSION 3.1.3)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON) # not necessary, but encouraged The 3.1.3 minimum version is important, as that's when So the compiler errors you are seeing are almost certainly because you need to compile your library with C++11. NOTE: I advise doing it at the beginning because this has to be done before your CMake "target" is created. If the target is created before you set # DOES work
set(CMAKE_CXX_STANDARD 11)
add_executable(myExe main.cpp) # compiled with c++11
# does NOT work
add_executable(myExe main.cpp)
set(CMAKE_CXX_STANDARD 11) # does not apply to `myExe`
This is independent of the compiler errors you have. In C++ there's something called "ABI", where
This would always get triggered for you on OSX unless you are using a non-default compiler. I hope that helps get you in the right direction :) |
This was needed to have this compile on my macos machine. Before, I ran into errors like "error: delegating constructors are permitted only in C++11" Found the fix searching for that in this issue: wjakob/nanogui#302 Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
I have been developing a C++ OpenGL game project. CMake is used as the build system. I'm using nanogui in the project as the external GUI library.
I was using glfw and glad outside of the nanogui and I managed to link them externally to the nanogui's CMake.
Everything successfully built and until up here
In file included from /Users/firat/Desktop/dungeon-defense/main.cpp:11:
In file included from /Users/firat/Desktop/dungeon-defense/include/GUI.h:5:
In file included from /Users/firat/Desktop/dungeon-defense/external/nanogui/include/nanogui/nanogui.h:14:
/Users/firat/Desktop/dungeon-defense/external/nanogui/include/nanogui/common.h:124:6: warning: scoped enumerations are a C++11 extension [-Wc++11-extensions]
enum class Cursor {
^
/Users/firat/Desktop/dungeon-defense/external/nanogui/include/nanogui/common.h:136:18: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using Vector2f = Eigen::Vector2f;
^
/Users/firat/Desktop/dungeon-defense/external/nanogui/include/nanogui/common.h:138:18: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using Vector3f = Eigen::Vector3f;
^
/Users/firat/Desktop/dungeon-defense/external/nanogui/include/nanogui/common.h:140:18: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using Vector4f = Eigen::Vector4f;
^
/Users/firat/Desktop/dungeon-defense/external/nanogui/include/nanogui/common.h:142:18: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using Vector2i = Eigen::Vector2i;
^
/Users/firat/Desktop/dungeon-defense/external/nanogui/include/nanogui/common.h:144:18: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using Vector3i = Eigen::Vector3i;
^
/Users/firat/Desktop/dungeon-defense/external/nanogui/include/nanogui/common.h:146:18: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using Vector4i = Eigen::Vector4i;
^
/Users/firat/Desktop/dungeon-defense/external/nanogui/include/nanogui/common.h:148:18: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using Matrix3f = Eigen::Matrix3f;
^
/Users/firat/Desktop/dungeon-defense/external/nanogui/include/nanogui/common.h:150:18: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using Matrix4f = Eigen::Matrix4f;
^
/Users/firat/Desktop/dungeon-defense/external/nanogui/include/nanogui/common.h:152:18: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using VectorXf = Eigen::VectorXf;
^
/Users/firat/Desktop/dungeon-defense/external/nanogui/include/nanogui/common.h:154:18: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using MatrixXf = Eigen::MatrixXf;
^
/Users/firat/Desktop/dungeon-defense/external/nanogui/include/nanogui/common.h:160:18: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using MatrixXu = Eigen::Matrix<uint32_t, Eigen::Dynamic, Eigen::Dynamic>;
^
/Users/firat/Desktop/dungeon-defense/external/nanogui/include/nanogui/common.h:195:15: error: delegating constructors are permitted only in C++11
Color() : Color(0, 0, 0, 0) {}
^~~~~
/Users/firat/Desktop/dungeon-defense/external/nanogui/include/nanogui/common.h:216:11: error: delegating constructors are permitted only in C++11
: Color(color(0), color(1), color(2), alpha) { }
^~~~~
/Users/firat/Desktop/dungeon-defense/external/nanogui/include/nanogui/common.h:231:11: error: delegating constructors are permitted only in C++11
: Color(color.cast() / 255.f, alpha / 255.f) { }
^~~~~
/Users/firat/Desktop/dungeon-defense/external/nanogui/include/nanogui/common.h:240:43: error: delegating constructors are permitted only in C++11
Color(const Eigen::Vector3f &color) : Color(color, 1.0f) {}
^~~~~
/Users/firat/Desktop/dungeon-defense/external/nanogui/include/nanogui/common.h:250:11: error: delegating constructors are permitted only in C++11
: Color((Vector3f)(color.cast() / 255.f)) { }
^~~~~
/Users/firat/Desktop/dungeon-defense/external/nanogui/include/nanogui/common.h:260:11: error: delegating constructors are permitted only in C++11
: Color((Vector4f)(color.cast() / 255.f)) { }
^~~~~
/Users/firat/Desktop/dungeon-defense/external/nanogui/include/nanogui/common.h:272:11: error: delegating constructors are permitted only in C++11
: Color(Vector3f::Constant(intensity), alpha) { }
^~~~~
/Users/firat/Desktop/dungeon-defense/external/nanogui/include/nanogui/common.h:285:11: error: delegating constructors are permitted only in C++11
: Color(Vector3i::Constant(intensity), alpha) { }
^~~~~
/Users/firat/Desktop/dungeon-defense/external/nanogui/include/nanogui/common.h:302:49: error: delegating constructors are permitted only in C++11
Color(float r, float g, float b, float a) : Color(Vector4f(r, g, b, a)) { }
^~~~~
/Users/firat/Desktop/dungeon-defense/external/nanogui/include/nanogui/common.h:320:41: error: delegating constructors are permitted only in C++11
Color(int r, int g, int b, int a) : Color(Vector4i(r, g, b, a)) { }
^~~~~
/Users/firat/Desktop/dungeon-defense/external/nanogui/include/nanogui/common.h:475:65: error: a space is required between consecutive right angle brackets (use '> >')
file_dialog(const std::vector<std::pair<std::string, std::string>> &filetypes,
^~
> >
/Users/firat/Desktop/dungeon-defense/external/nanogui/include/nanogui/common.h:494:65: error: a space is required between consecutive right angle brackets (use '> >')
file_dialog(const std::vector<std::pair<std::string, std::string>> &filetypes,
^~
> >
/Users/firat/Desktop/dungeon-defense/external/nanogui/include/nanogui/common.h:521:61: error: a space is required between consecutive right angle brackets (use '> >')
extern NANOGUI_EXPORT std::vector<std::pair<int, std::string>>
^~
> >
In file included from /Users/firat/Desktop/dungeon-defense/main.cpp:11:
In file included from /Users/firat/Desktop/dungeon-defense/include/GUI.h:5:
In file included from /Users/firat/Desktop/dungeon-defense/external/nanogui/include/nanogui/nanogui.h:15:
In file included from /Users/firat/Desktop/dungeon-defense/external/nanogui/include/nanogui/widget.h:15:
/Users/firat/Desktop/dungeon-defense/external/nanogui/include/nanogui/object.h:45:43: error: expected ';' at end of declaration list
void decRef(bool dealloc = true) const noexcept;
^
;
/Users/firat/Desktop/dungeon-defense/external/nanogui/include/nanogui/object.h:52:30: error: function definition does not declare parameters
mutable std::atomic m_refCount { 0 };
^
/Users/firat/Desktop/dungeon-defense/external/nanogui/include/nanogui/object.h:31:30: error: member initializer 'm_refCount' does not name a non-static data member or base class
Object(const Object &) : m_refCount(0) {}
^~~~~~~~~~~~~
/Users/firat/Desktop/dungeon-defense/external/nanogui/include/nanogui/object.h:34:38: error: use of undeclared identifier 'm_refCount'; did you mean 'getRefCount'?
int getRefCount() const { return m_refCount; };
^~~~~~~~~~
getRefCount
/Users/firat/Desktop/dungeon-defense/external/nanogui/include/nanogui/object.h:34:9: note: 'getRefCount' declared here
int getRefCount() const { return m_refCount; };
^
/Users/firat/Desktop/dungeon-defense/external/nanogui/include/nanogui/object.h:37:29: error: use of undeclared identifier 'm_refCount'
void incRef() const { ++m_refCount; }
^
/Users/firat/Desktop/dungeon-defense/external/nanogui/include/nanogui/object.h:87:13: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
ref(ref &&r) noexcept : m_ptr(r.m_ptr) {
^
/Users/firat/Desktop/dungeon-defense/external/nanogui/include/nanogui/object.h:87:17: error: expected ';' at end of declaration list
ref(ref &&r) noexcept : m_ptr(r.m_ptr) {
^
;
fatal error: too many errors emitted, stopping now [-ferror-limit=]
13 warnings and 20 errors generated.
make[3]: *** [CMakeFiles/dungeon-defense.dir/main.cpp.o] Error 1
make[2]: *** [CMakeFiles/dungeon-defense.dir/all] Error 2
make[1]: *** [CMakeFiles/dungeon-defense.dir/rule] Error 2
make: *** [dungeon-defense] Error 2
From what I can understand, it has something to do with the compiler not being c++11.
if (POLICY CMP0058)
cmake_policy(SET CMP0058 NEW)
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
What do you think about it, what could be the problem? If you need more information let me know!
The text was updated successfully, but these errors were encountered: