undefined reference to `SOIL_load_OGL_texture'?

夙愿已清 提交于 2019-12-10 21:11:55

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!