Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling GLUI library, VS2010 gives me a weird namespace error

I've got an OpenGL project for a class I'm in, and it's based on GLUI. The provided GLUI library won't work which is why I'm trying to compile it myself. So, I downloaded the source code from SourceForge and try to compile the _glui library. It gives me this, and I can't find any information on it:

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

etc, etc etc

I look at the glui.h source file, and lines 1718 and 1719 have this:

#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

Anyone seen this before?

like image 976
jakev Avatar asked Dec 06 '25 07:12

jakev


2 Answers

I just come across this problem. then I do following,you can try.

(1) download the lastest vision from gib.
(2) use vs2010 build it.
(3) you will come across the problem

#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

just get the code out of class, rebuild again.
(4) you will generate glui.lib.
(5) use the glui.lib,and the glui.h

like image 166
user2681341 Avatar answered Dec 08 '25 09:12

user2681341


You cannot explicitly instantiate a template inside a function or a class. try moving it outside the function or class. Or is it a library?

like image 36
Chand Priyankara Avatar answered Dec 08 '25 09:12

Chand Priyankara



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!