godot-cpp icon indicating copy to clipboard operation
godot-cpp copied to clipboard

Compiling a GDNative library with `godot-cpp` on macOS fails due to too many warnings

Open aaronfranke opened this issue 2 years ago • 3 comments

macOS 10.15.7, Apple clang version 12.0.0, compiling the simple GDNative C++ demo as of https://github.com/godotengine/gdnative-demos/pull/52.

When I compile with scons p=osx, these warnings and errors are generated, and the builds fails:

clang++ -o src/Simple.os -c -g -O2 -arch x86_64 -fPIC -Igodot-cpp/godot-headers -Igodot-cpp/include -Igodot-cpp/include/gen -Igodot-cpp/include/core src/Simple.cpp
In file included from src/Simple.cpp:1:
In file included from src/Simple.hpp:1:
In file included from godot-cpp/include/core/Godot.hpp:11:
In file included from godot-cpp/include/core/CoreTypes.hpp:4:
godot-cpp/include/core/Defs.hpp:6:6: warning: scoped enumerations are a C++11 extension [-Wc++11-extensions]
enum class Error {
     ^
In file included from src/Simple.cpp:1:
In file included from src/Simple.hpp:1:
In file included from godot-cpp/include/core/Godot.hpp:11:
In file included from godot-cpp/include/core/CoreTypes.hpp:4:
In file included from godot-cpp/include/core/Defs.hpp:62:
In file included from godot-cpp/include/core/GodotGlobal.hpp:4:
In file included from godot-cpp/include/core/Array.hpp:6:
godot-cpp/include/core/String.hpp:43:16: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
        String(String &&other);
                      ^
godot-cpp/include/core/String.hpp:59:24: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
        void operator=(String &&s);
                              ^
In file included from src/Simple.cpp:1:
In file included from src/Simple.hpp:1:
In file included from godot-cpp/include/core/Godot.hpp:11:
In file included from godot-cpp/include/core/CoreTypes.hpp:4:
In file included from godot-cpp/include/core/Defs.hpp:62:
In file included from godot-cpp/include/core/GodotGlobal.hpp:4:
godot-cpp/include/core/Array.hpp:17:48: warning: variadic templates are a C++11 extension [-Wc++11-extensions]
template <typename T, typename ValueT, typename... Args>
                                               ^
godot-cpp/include/core/Array.hpp:34:64: warning: variadic templates are a C++11 extension [-Wc++11-extensions]
template <typename KV, typename KeyT, typename ValueT, typename... Args>
                                                               ^
godot-cpp/include/core/Array.hpp:86:17: warning: variadic templates are a C++11 extension [-Wc++11-extensions]
        template <class... Args>
                       ^
In file included from src/Simple.cpp:1:
In file included from src/Simple.hpp:1:
In file included from godot-cpp/include/core/Godot.hpp:11:
In file included from godot-cpp/include/core/CoreTypes.hpp:4:
In file included from godot-cpp/include/core/Defs.hpp:62:
godot-cpp/include/core/GodotGlobal.hpp:38:17: warning: variadic templates are a C++11 extension [-Wc++11-extensions]
        template <class... Args>
                       ^
In file included from src/Simple.cpp:1:
In file included from src/Simple.hpp:1:
In file included from godot-cpp/include/core/Godot.hpp:11:
In file included from godot-cpp/include/core/CoreTypes.hpp:8:
godot-cpp/include/core/Basis.hpp:66:12: error: union member 'elements' has a non-trivial default constructor
                        Vector3 elements[3]; // Not for direct access, use [] operator instead
                                ^
godot-cpp/include/core/Vector3.hpp:52:9: note: because type 'godot::Vector3' has a user-provided default constructor
        inline Vector3() {
               ^
In file included from src/Simple.cpp:1:
In file included from src/Simple.hpp:1:
In file included from godot-cpp/include/core/Godot.hpp:11:
In file included from godot-cpp/include/core/CoreTypes.hpp:8:
godot-cpp/include/core/Basis.hpp:289:11: error: union member 'elements' has a non-trivial default constructor
                Vector3 elements[3]; // Not for direct access, use [] operator instead
                        ^
godot-cpp/include/core/Vector3.hpp:52:9: note: because type 'godot::Vector3' has a user-provided default constructor
        inline Vector3() {
               ^
In file included from src/Simple.cpp:1:
In file included from src/Simple.hpp:1:
In file included from godot-cpp/include/core/Godot.hpp:11:
In file included from godot-cpp/include/core/CoreTypes.hpp:8:
godot-cpp/include/core/Basis.hpp:78:4: error: use of undeclared identifier 'elements'
                        elements[0][column] = p_value.x;
                        ^
godot-cpp/include/core/Basis.hpp:79:4: error: use of undeclared identifier 'elements'
                        elements[1][column] = p_value.y;
                        ^
godot-cpp/include/core/Basis.hpp:80:4: error: use of undeclared identifier 'elements'
                        elements[2][column] = p_value.z;
                        ^
godot-cpp/include/core/Basis.hpp:85:19: error: use of undeclared identifier 'elements'
                        return Vector3(elements[0][column], elements[1][column], elements[2][column]);
                                       ^
godot-cpp/include/core/Basis.hpp:85:40: error: use of undeclared identifier 'elements'
                        return Vector3(elements[0][column], elements[1][column], elements[2][column]);
                                                            ^
godot-cpp/include/core/Basis.hpp:85:61: error: use of undeclared identifier 'elements'
                        return Vector3(elements[0][column], elements[1][column], elements[2][column]);
                                                                                 ^
godot-cpp/include/core/Basis.hpp:93:11: error: use of undeclared identifier 'elements'
                        return elements[p_axis][column];
                               ^
godot-cpp/include/core/Basis.hpp:97:11: error: use of undeclared identifier 'elements'
                        return elements[p_axis][column];
                               ^
godot-cpp/include/core/Basis.hpp:293:3: error: use of undeclared identifier 'elements'
                elements[0] = p_basis.elements[0];
                ^
godot-cpp/include/core/Basis.hpp:293:25: error: no member named 'elements' in 'godot::Basis'
                elements[0] = p_basis.elements[0];
                              ~~~~~~~ ^
godot-cpp/include/core/Basis.hpp:294:3: error: use of undeclared identifier 'elements'
                elements[1] = p_basis.elements[1];
                ^
godot-cpp/include/core/Basis.hpp:294:25: error: no member named 'elements' in 'godot::Basis'
                elements[1] = p_basis.elements[1];
                              ~~~~~~~ ^
godot-cpp/include/core/Basis.hpp:295:3: error: use of undeclared identifier 'elements'
                elements[2] = p_basis.elements[2];
                ^
godot-cpp/include/core/Basis.hpp:295:25: error: no member named 'elements' in 'godot::Basis'
                elements[2] = p_basis.elements[2];
                              ~~~~~~~ ^
godot-cpp/include/core/Basis.hpp:299:3: error: use of undeclared identifier 'elements'
                elements[0] = p_basis.elements[0];
                ^
godot-cpp/include/core/Basis.hpp:299:25: error: no member named 'elements' in 'godot::Basis'
                elements[0] = p_basis.elements[0];
                              ~~~~~~~ ^
godot-cpp/include/core/Basis.hpp:300:3: error: use of undeclared identifier 'elements'
                elements[1] = p_basis.elements[1];
                ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
7 warnings and 20 errors generated.
scons: *** [src/Simple.os] Error 1
scons: building terminated because of errors.

aaronfranke avatar Jul 07 '21 03:07 aaronfranke

You might need to add -std=c++14 to CCFLAGS:

See https://github.com/godotengine/godot-cpp/blob/3.3/SConstruct#L220

Faless avatar Jul 08 '21 21:07 Faless

@Faless Yes, that works! But three things:

  • Why is this required on macOS and iOS but not Windows or Linux? Is this Apple's requirement?
  • This should be documented in the README.
  • Is it possible for godot-cpp to give a more descriptive error message? Like preprocessor directives to fail on old C++ versions?

aaronfranke avatar Jul 09 '21 01:07 aaronfranke

Why is this required on macOS and iOS but not Windows or Linux? Is this Apple's requirement?

I think on other platforms the default C++ version is >= 14

This should be documented in the README.

Agreed.

Is it possible for godot-cpp to give a more descriptive error message? Like preprocessor directives to fail on old C++ versions?

Documenting it is probably enough but yeah, there should be a preprocessor macro to check the C++ version.

Faless avatar Jul 09 '21 02:07 Faless