可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
This question already has an answer here:
Original Question:
[Warning] passing GLfloat' for converting 2 of
void glutSolidSphere(GLdouble, GLint, GLint)'
[Warning] passing GLfloat' for converting 3 of
void glutSolidSphere(GLdouble, GLint, GLint)'
After applying one of the poster's suggestions of including glut.h, I now get this problem.
I can't use glutSolidSphere() without it.
[Linker error] undefined reference to `__glutInitWithExit@12'
[Linker error] undefined reference to `__glutCreateWindowWithExit@8'
[Linker error] undefined reference to `__glutCreateMenuWithExit@8'
[Linker error] undefined reference to `glutSolidSphere@16'
I'm using DEV C++, if that helps.
回答1:
That looks mangled. Perhaps it's telling you that you're passing a GLfloat
where a GLint
was expected, as the 2nd and 3rd arguments? Please paste your exact error/warning output again, this doesn't look right.
回答2:
The 'slices' and 'stacks' params are supposed to be integers; your code is passing in floats.
Edit: you really shouldn't edit your question to make it a completely different question. Undefined Reference means that you aren't linking in the library that contains those functions. You need to include GLuT in the list of libraries you're linking against.
回答3:
As DNS said, but in simpler terms:
You need to link the GLUT library. I believe it is usually glut32.lib on Win32 machines. There should be an option for this somewhere in the project properties pages of your IDE; Sorry, I don't use Dev-C++, but in Visual Studio it is in the project properties, and then linker settings, and "Additional Library Includes".
回答4:
Pass -lglut32
option to mingw's linker - Dev-Cpp uses mingw.
You'll have to find "linker options" textbox somewhere in Project Options. Sorry I cannot be more specific than that, it's been over a year since I used Dev-Cpp, and over three years since I really used it. It should be the same place where you added -lopengl32
and -lglu32
.
Don't forget to install the GLUT devpak.
回答5:
GLUTMingw32.zip file contains all files necessary to build under devcpp I extracted it on desktop . added lib and include directories from devcpp project-project options menu to include and lib directories . after added in project options dialog on parameters tab - > linker :
../../../../Dev-Cpp/lib/libopengl32.a
../../../../Dev-Cpp/lib/libglu32.a
../GLUTMingw32/GLUTMingw32/lib/libglut32.a
first two are in devcpp install dir/lib folder /you can use -lopengl32 and -lglu32 instead , it works/
third one ,libglut32.a , I added from extracted GLUTMingw32.zip folder
placed glut32.dll in folder where project got generated and main.cpp resides
thats all . after I got Permission denied I just removed generated exe file and recompiled if exe can't be deleted close devcpp
if it complains about short redefinition
add at the top of main.cpp "# define _WCHAR_T_DEFINED"
without quotes