我有一个我正在上课的OpenGL项目,它基于GLUI。提供的GLUI库不起作用,这就是为什么我要自己编译它。所以,我从SourceForge下载了源代码并尝试编译_glui库。它给了我这个,我找不到任何关于它的信息:
1>ClCompile:
1> algebra3.cpp
1> arcball.cpp
1> glui.cpp
1>c:\users\jake\downloads\glui-2.36\glui-2.36\src\include\gl\glui.h(1718): error C2252: an explicit instantiation of a template can only occur at namespace scope
1>c:\users\jake\downloads\glui-2.36\glui-2.36\src\include\gl\glui.h(1719): error C2252: an explicit instantiation of a template can only occur at namespace scope
1> glui_add_controls.cpp
1>c:\users\jake\downloads\glui-2.36\glui-2.36\src\include\gl\glui.h(1718): error C2252: an explicit instantiation of a template can only occur at namespace scope
1>c:\users\jake\downloads\glui-2.36\glui-2.36\src\include\gl\glui.h(1719): error C2252: an explicit instantiation of a template can only occur at namespace scope
1> glui_bitmap_img_data.cpp
1> glui_bitmaps.cpp
1>c:\users\jake\downloads\glui-2.36\glui-2.36\src\include\gl\glui.h(1718): error C2252: an explicit instantiation of a template can only occur at namespace scope
1>c:\users\jake\downloads\glui-2.36\glui-2.36\src\include\gl\glui.h(1719): error C2252: an explicit instantiation of a template can only occur at namespace scope
1> glui_button.cpp
1>c:\users\jake\downloads\glui-2.36\glui-2.36\src\include\gl\glui.h(1718): error C2252: an explicit instantiation of a template can only occur at namespace scope
1>c:\users\jake\downloads\glui-2.36\glui-2.36\src\include\gl\glui.h(1719): error C2252: an explicit instantiation of a template can only occur at namespace scope
1> glui_checkbox.cpp
1>c:\users\jake\downloads\glui-2.36\glui-2.36\src\include\gl\glui.h(1718): error C2252: an explicit instantiation of a template can only occur at namespace scope
1>c:\users\jake\downloads\glui-2.36\glui-2.36\src\include\gl\glui.h(1719): error C2252: an explicit instantiation of a template can only occur at namespace scope
1> glui_column.cpp
等等等等
我查看了glui.h源文件,第1718和1719行有:
#ifdef _MSC_VER
// Explicit template instantiation needed for dll
template class GLUIAPI std::allocator<GLUI_String>;
template class GLUIAPI std::vector<GLUI_String, std::allocator<GLUI_String> >;
#endif
之前有人见过这个吗?
答案 0 :(得分:3)
我刚遇到这个问题。 然后我做了以下,你可以试试。
(1)从gib下载最新的愿景
(2)使用vs2010构建它。
(3)你会遇到问题
#ifdef _MSC_VER
// Explicit template instantiation needed for dll
template class GLUIAPI std::allocator<GLUI_String>;
template class GLUIAPI std::vector<GLUI_String, std::allocator<GLUI_String> >;
#endif
只是让代码退出课堂,再次重建。
(4)你将生成glui.lib
(5)使用glui.lib和glui.h
答案 1 :(得分:2)
您无法在函数或类中显式实例化模板。 尝试将其移到函数或类之外。 或者它是一个图书馆?
答案 2 :(得分:1)
如果有人有更多信息,我会很高兴听到它,但我发现在glui.h中注释掉这一部分允许它编译。现在我们将了解编译的库是否真的有效....