问题
I am don't know why this keeps saying:
undefined reference to "SOIL_load_OGL_texture
This is the code:
GLuint loadtex( const char* texname )
{
GLuint texture = SOIL_load_OGL_texture(
texname,
SOIL_LOAD_AUTO,
SOIL_CREATE_NEW_ID,
SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT
);
glBindTexture( GL_TEXTURE_2D, texture );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
return texture;
}
I have
#include <SOIL.h>
回答1:
It turns out you have to link libSOIL before linking libopengl32. So, for example: g++ -g source.cpp -lglu32 -lSOIL -lopengl32 -lfreeglut
will work, but leaving libSOIL last will result in the error above.
回答2:
Look in "Simple OpenGL Image Library/projects/makefile", then create a directory there called "obj". Now run "make" from commandline where the makefile is and then "make install". That should install the library and header file. Try compiling now; it worked for me. If you receive any errors about libm, just add "-lm" to your linking options.
回答3:
undefined reference mean that you need link soil library to your application. There are different ways to do it, it depends on platform and compiler that you used. On Linux you need add something like -lsoil to linker flags.
回答4:
you have to link against the SOIL library:
g++ -o output your-source.cpp -lSOIL
SOIL has to be in caps
来源:https://stackoverflow.com/questions/17497497/undefined-reference-to-soil-load-ogl-texture