GLM:无法再编译

GLM: Can't compile anymore

本文关键字:编译 GLM      更新时间:2023-10-16

还有人在使用这个库吗?

去年对我来说工作得很好,但现在我的代码无法编译:

(在使用GCC 4.6.1的MinGW上):

In file included from ../include/glm/./core/func_packing.hpp:190:0,
                 from ../include/glm/glm.hpp:103,
                 from SmoothRenderer.cpp:11:
../include/glm/./core/func_packing.inl: In function 'glm::detail::uint32 glm::packUnorm4x8(const glm::detail::tvec4<float>&)':
../include/glm/./core/func_packing.inl:84:17: error: expected primary-expression before '(' token
../include/glm/./core/func_packing.inl:84:17: error: expected primary-expression before ')' token
../include/glm/./core/func_packing.inl:84:17: error: expected ';' before 'round'
../include/glm/./core/func_packing.inl:85:26: error: 'D' was not declared in this scope
../include/glm/./core/func_packing.inl: In function 'glm::detail::tvec4<float> glm::unpackUnorm4x8(const uint32&)':
../include/glm/./core/func_packing.inl:94:38: warning: statement has no effect [-Wunused-value]
../include/glm/./core/func_packing.inl:99:4: error: 'D' was not declared in this scope

这是最新版本0.9.4.3。

我的Mac上也有类似的问题:

In file included from SmoothRenderer.cpp:10:
In file included from ../include/glm/glm.hpp:103:
In file included from ../include/glm/./core/func_packing.hpp:190:
../include/glm/core/func_packing.inl:84:33: error: expected '(' for function-style cast or type construction
                detail::uint8 D((detail::uint8)round(clamp(v.w, 0.0f, 1.0f) * 255.0f));
                                 ~~~~~~~~~~~~~^
./util.h:330:15: note: expanded from macro 'D'
# define D(x) x
              ^
In file included from SmoothRenderer.cpp:10:
In file included from ../include/glm/glm.hpp:103:
In file included from ../include/glm/./core/func_packing.hpp:190:
../include/glm/core/func_packing.inl:85:26: error: use of undeclared identifier 'D'
                return detail::uint32((D << 24) | (C << 16) | (B << 8) | A);
                                       ^
../include/glm/core/func_packing.inl:99:4: error: use of undeclared identifier 'D'
                        D * 1.0f / 255.0f);
                        ^
../include/glm/core/func_packing.inl:94:30: warning: expression result unused [-Wunused-value]
                detail::uint32 D((p >> 24) & Mask8);
                ~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~
./util.h:330:15: note: expanded from macro 'D'
# define D(x) x
              ^
In file included from SmoothRenderer.cpp:10:
In file included from ../include/glm/glm.hpp:108:
In file included from ../include/glm/./core/func_noise.hpp:85:
../include/glm/core/func_noise.inl:125:33: error: too many arguments provided to function-like macro invocation
                detail::tvec4<T> const D(0.0, 0.5, 1.0, 2.0);
                                              ^
../include/glm/core/func_noise.inl:125:27: error: expected ';' at end of declaration
                detail::tvec4<T> const D(0.0, 0.5, 1.0, 2.0);
                                        ^
                                        ;

这是一个头文件库。这样的事情不应该发生…

我只使用一些4x4矩阵乘法和反演。由于我的应用程序的其余部分广泛使用了LAPACK,所以我并不真正需要glm来做什么。但我讨厌我的代码,我试图使它非常可移植的随机破坏像这样。

是的,这原来是一个问题与D宏。该死,问我问题4分钟后才回答。这就是解释问题的美妙之处。有一半的时间这就足够了。

这是避免使用预处理器的又一个原因。疯狂的错误。尽管如此,值得称赞的是,clang非常好,不仅提到了其他地方定义的宏的一些问题,它甚至把它复制到那里给我看。