GLM 无法使用 g++/C++11 进行编译
GLM fails to compile with g++/C++11
我正在尝试将 GLM 用于游戏项目,但是在使用 g++ 和 -std=c++11 进行编译时,出现了很多编译错误。
这是我要编译的代码:(摘自 here)
#include "glm/vec3.hpp"
#include "glm/gtx/io.hpp"
#include <iostream>
using namespace std;
using glm::vec3;
int main () {
vec3 i_am_zero;
cout << i_am_zero << endl;
return 0;
}
我的命令行:
g++ -std=c++11 test.cpp -o test.exe
编译器输出:
In file included from glm/gtx/../detail/func_trigonometric.hpp:205:0,
from glm/gtx/../trigonometric.hpp:35,
from glm/gtx/../glm.hpp:110,
from glm/gtx/io.hpp:50,
from glmtest.cpp:2:
glm/gtx/../detail/func_trigonometric.inl:166:14: error: 'std::asinh' has not been declared
using std::asinh;
^
In file included from glm/gtx/../detail/func_trigonometric.hpp:205:0,
from glm/gtx/../trigonometric.hpp:35,
from glm/gtx/../glm.hpp:110,
from glm/gtx/io.hpp:50,
from glmtest.cpp:2:
glm/gtx/../detail/func_trigonometric.inl:185:14: error: 'std::acosh' has not been declared
using std::acosh;
^
glm/gtx/../detail/func_trigonometric.inl:206:14: error: 'std::atanh' has not been declared
using std::atanh;
^
In file included from glm/gtx/../detail/func_exponential.hpp:132:0,
from glm/gtx/../exponential.hpp:35,
from glm/gtx/../glm.hpp:111,
from glm/gtx/io.hpp:50,
from glmtest.cpp:2:
glm/gtx/../detail/func_exponential.inl:43:14: error: 'std::log2' has not been declared
using std::log2;
^
In file included from glm/gtx/../detail/func_common.hpp:455:0,
from glm/gtx/../common.hpp:35,
from glm/gtx/../glm.hpp:112,
from glm/gtx/io.hpp:50,
from glmtest.cpp:2:
glm/gtx/../detail/func_common.inl:229:16: error: 'std::trunc' has not been declared
using ::std::trunc;
^
glm/gtx/../detail/func_common.inl:248:16: error: 'std::round' has not been declared
using ::std::round;
^
glm/gtx/../detail/func_common.inl: In instantiation of 'vecType<T, P> glm::round(const vecType<T, P>&) [with T = float; glm::precision P = (glm::precision)0u; vecType = glm::tvec2]':
glm/gtx/../detail/func_packing.inl:47:55: required from here
glm/gtx/../detail/func_common.inl:262:59: error: no matching function for call to 'glm::detail::functor1<float, float, (glm::precision)0u, glm::tvec2>::call(<unresolved overloaded function type>, const glm::tvec2<float, (glm::precision)0u>&)'
return detail::functor1<T, T, P, vecType>::call(round, x);
^
glm/gtx/../detail/func_common.inl:262:59: note: candidate is:
In file included from glm/gtx/../detail/func_trigonometric.inl:33:0,
from glm/gtx/../detail/func_trigonometric.hpp:205,
from glm/gtx/../trigonometric.hpp:35,
from glm/gtx/../glm.hpp:110,
from glm/gtx/io.hpp:50,
from glmtest.cpp:2:
glm/gtx/../detail/_vectorize.hpp:58:41: note: static glm::tvec2<R, P> glm::detail::functor1<R, T, P, glm::tvec2>::call(R (*)(T), const glm::tvec2<T, P>&) [with R = float; T = float; glm::precision P = (glm::precision)0u]
GLM_FUNC_QUALIFIER static tvec2<R, P> call(R (*Func) (T x), tvec2<T, P> const & v)
^
glm/gtx/../detail/_vectorize.hpp:58:41: note: no known conversion for argument 1 from '<unresolved overloaded function type>' to 'float (*)(float)'
In file included from glm/gtx/../detail/func_common.hpp:455:0,
from glm/gtx/../common.hpp:35,
from glm/gtx/../glm.hpp:112,
from glm/gtx/io.hpp:50,
from glmtest.cpp:2:
glm/gtx/../detail/func_common.inl: In instantiation of 'vecType<T, P> glm::round(const vecType<T, P>&) [with T = float; glm::precision P = (glm::precision)0u; vecType = glm::tvec4]':
glm/gtx/../detail/func_packing.inl:105:52: required from here
glm/gtx/../detail/func_common.inl:262:59: error: no matching function for call to 'glm::detail::functor1<float, float, (glm::precision)0u, glm::tvec4>::call(<unresolved overloaded function type>, const glm::tvec4<float, (glm::precision)0u>&)'
return detail::functor1<T, T, P, vecType>::call(round, x);
^
glm/gtx/../detail/func_common.inl:262:59: note: candidate is:
In file included from glm/gtx/../detail/func_trigonometric.inl:33:0,
from glm/gtx/../detail/func_trigonometric.hpp:205,
from glm/gtx/../trigonometric.hpp:35,
from glm/gtx/../glm.hpp:110,
from glm/gtx/io.hpp:50,
from glmtest.cpp:2:
glm/gtx/../detail/_vectorize.hpp:76:41: note: static glm::tvec4<R, P> glm::detail::functor1<R, T, P, glm::tvec4>::call(R (*)(T), const glm::tvec4<T, P>&) [with R = float; T = float; glm::precision P = (glm::precision)0u]
GLM_FUNC_QUALIFIER static tvec4<R, P> call(R (*Func) (T x), tvec4<T, P> const & v)
^
glm/gtx/../detail/_vectorize.hpp:76:41: note: no known conversion for argument 1 from '<unresolved overloaded function type>' to 'float (*)(float)'
它似乎无法从 cmath 中找到某些函数 - 但如果我在包含 glm 之前包含 cmath,这些错误仍然存在。
有什么建议吗?
这在我的机器上以 c++11 标准使用 gcc 4.8.2 编译和运行得很好。
我收到一系列警告
/usr/include/glm/gtc/quaternion.inl:639:165: note: #pragma message: GLM: rotate function taking degrees as a parameter is deprecated. #define GLM_FORCE_RADIANS before including GLM headers to remove this message.
但是如果我将代码更改为
#define GLM_FORCE_RADIANS
#include "glm/vec3.hpp"
#include "glm/gtx/io.hpp"
#include <iostream>
using namespace std;
using glm::vec3;
int main () {
vec3 i_am_zero;
cout << i_am_zero << endl;
return 0;
}
然后用 -Wall -Werror
编译很好。
glm header 包含 cmath
,因此再次包含它不会对您有所改变。
我正在使用 GLM 版本 0.9.5。您可能想要升级您的 GLM 版本和/或编译器版本?
这似乎是 GLM 0.9.7 版的错误。降级到 0.9.5 为我解决了这个问题。它被跟踪为 issue 405.
我正在尝试将 GLM 用于游戏项目,但是在使用 g++ 和 -std=c++11 进行编译时,出现了很多编译错误。
这是我要编译的代码:(摘自 here)
#include "glm/vec3.hpp"
#include "glm/gtx/io.hpp"
#include <iostream>
using namespace std;
using glm::vec3;
int main () {
vec3 i_am_zero;
cout << i_am_zero << endl;
return 0;
}
我的命令行:
g++ -std=c++11 test.cpp -o test.exe
编译器输出:
In file included from glm/gtx/../detail/func_trigonometric.hpp:205:0,
from glm/gtx/../trigonometric.hpp:35,
from glm/gtx/../glm.hpp:110,
from glm/gtx/io.hpp:50,
from glmtest.cpp:2:
glm/gtx/../detail/func_trigonometric.inl:166:14: error: 'std::asinh' has not been declared
using std::asinh;
^
In file included from glm/gtx/../detail/func_trigonometric.hpp:205:0,
from glm/gtx/../trigonometric.hpp:35,
from glm/gtx/../glm.hpp:110,
from glm/gtx/io.hpp:50,
from glmtest.cpp:2:
glm/gtx/../detail/func_trigonometric.inl:185:14: error: 'std::acosh' has not been declared
using std::acosh;
^
glm/gtx/../detail/func_trigonometric.inl:206:14: error: 'std::atanh' has not been declared
using std::atanh;
^
In file included from glm/gtx/../detail/func_exponential.hpp:132:0,
from glm/gtx/../exponential.hpp:35,
from glm/gtx/../glm.hpp:111,
from glm/gtx/io.hpp:50,
from glmtest.cpp:2:
glm/gtx/../detail/func_exponential.inl:43:14: error: 'std::log2' has not been declared
using std::log2;
^
In file included from glm/gtx/../detail/func_common.hpp:455:0,
from glm/gtx/../common.hpp:35,
from glm/gtx/../glm.hpp:112,
from glm/gtx/io.hpp:50,
from glmtest.cpp:2:
glm/gtx/../detail/func_common.inl:229:16: error: 'std::trunc' has not been declared
using ::std::trunc;
^
glm/gtx/../detail/func_common.inl:248:16: error: 'std::round' has not been declared
using ::std::round;
^
glm/gtx/../detail/func_common.inl: In instantiation of 'vecType<T, P> glm::round(const vecType<T, P>&) [with T = float; glm::precision P = (glm::precision)0u; vecType = glm::tvec2]':
glm/gtx/../detail/func_packing.inl:47:55: required from here
glm/gtx/../detail/func_common.inl:262:59: error: no matching function for call to 'glm::detail::functor1<float, float, (glm::precision)0u, glm::tvec2>::call(<unresolved overloaded function type>, const glm::tvec2<float, (glm::precision)0u>&)'
return detail::functor1<T, T, P, vecType>::call(round, x);
^
glm/gtx/../detail/func_common.inl:262:59: note: candidate is:
In file included from glm/gtx/../detail/func_trigonometric.inl:33:0,
from glm/gtx/../detail/func_trigonometric.hpp:205,
from glm/gtx/../trigonometric.hpp:35,
from glm/gtx/../glm.hpp:110,
from glm/gtx/io.hpp:50,
from glmtest.cpp:2:
glm/gtx/../detail/_vectorize.hpp:58:41: note: static glm::tvec2<R, P> glm::detail::functor1<R, T, P, glm::tvec2>::call(R (*)(T), const glm::tvec2<T, P>&) [with R = float; T = float; glm::precision P = (glm::precision)0u]
GLM_FUNC_QUALIFIER static tvec2<R, P> call(R (*Func) (T x), tvec2<T, P> const & v)
^
glm/gtx/../detail/_vectorize.hpp:58:41: note: no known conversion for argument 1 from '<unresolved overloaded function type>' to 'float (*)(float)'
In file included from glm/gtx/../detail/func_common.hpp:455:0,
from glm/gtx/../common.hpp:35,
from glm/gtx/../glm.hpp:112,
from glm/gtx/io.hpp:50,
from glmtest.cpp:2:
glm/gtx/../detail/func_common.inl: In instantiation of 'vecType<T, P> glm::round(const vecType<T, P>&) [with T = float; glm::precision P = (glm::precision)0u; vecType = glm::tvec4]':
glm/gtx/../detail/func_packing.inl:105:52: required from here
glm/gtx/../detail/func_common.inl:262:59: error: no matching function for call to 'glm::detail::functor1<float, float, (glm::precision)0u, glm::tvec4>::call(<unresolved overloaded function type>, const glm::tvec4<float, (glm::precision)0u>&)'
return detail::functor1<T, T, P, vecType>::call(round, x);
^
glm/gtx/../detail/func_common.inl:262:59: note: candidate is:
In file included from glm/gtx/../detail/func_trigonometric.inl:33:0,
from glm/gtx/../detail/func_trigonometric.hpp:205,
from glm/gtx/../trigonometric.hpp:35,
from glm/gtx/../glm.hpp:110,
from glm/gtx/io.hpp:50,
from glmtest.cpp:2:
glm/gtx/../detail/_vectorize.hpp:76:41: note: static glm::tvec4<R, P> glm::detail::functor1<R, T, P, glm::tvec4>::call(R (*)(T), const glm::tvec4<T, P>&) [with R = float; T = float; glm::precision P = (glm::precision)0u]
GLM_FUNC_QUALIFIER static tvec4<R, P> call(R (*Func) (T x), tvec4<T, P> const & v)
^
glm/gtx/../detail/_vectorize.hpp:76:41: note: no known conversion for argument 1 from '<unresolved overloaded function type>' to 'float (*)(float)'
它似乎无法从 cmath 中找到某些函数 - 但如果我在包含 glm 之前包含 cmath,这些错误仍然存在。
有什么建议吗?
这在我的机器上以 c++11 标准使用 gcc 4.8.2 编译和运行得很好。
我收到一系列警告
/usr/include/glm/gtc/quaternion.inl:639:165: note: #pragma message: GLM: rotate function taking degrees as a parameter is deprecated. #define GLM_FORCE_RADIANS before including GLM headers to remove this message.
但是如果我将代码更改为
#define GLM_FORCE_RADIANS
#include "glm/vec3.hpp"
#include "glm/gtx/io.hpp"
#include <iostream>
using namespace std;
using glm::vec3;
int main () {
vec3 i_am_zero;
cout << i_am_zero << endl;
return 0;
}
然后用 -Wall -Werror
编译很好。
glm header 包含 cmath
,因此再次包含它不会对您有所改变。
我正在使用 GLM 版本 0.9.5。您可能想要升级您的 GLM 版本和/或编译器版本?
这似乎是 GLM 0.9.7 版的错误。降级到 0.9.5 为我解决了这个问题。它被跟踪为 issue 405.