SOIL: new lightweight image loading lib

Started by
129 comments, last by GenPFault 13 years, 11 months ago
Hey, so I was wondering if anyone could help with an issue I have compiling a game in cygwin.

Previously I wrote my own image loader for bitmaps, however, bitmaps kinda sucked in terms of size, so I wanted something to load PNGs. I decided to implement SOIL and it's worked perfectly under Mac OS X. However, when I attempt to compile the SOIL lib and then my game, I get the following errors due to undefined references:

$ makeg++ -Wall -o game_name.exe -I/usr/include/opengl -I/usr/include/w32api -I./Simple\ OpenGL\ Image\ Library/src drawable.cpp texture.cpp player.cpp character.cpp main.cpp map.cpp collideable.cpp state.cpp -L/usr/lib/w32api -L./Simple\ OpenGL\ Image\ Library/lib -lglut32 -lglu32 -lopengl32 -lSOIL./Simple OpenGL Image Library/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x253): undefined reference to `_glReadPixels'./Simple OpenGL Image Library/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x34a): undefined reference to `_glGetString'./Simple OpenGL Image Library/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x37c): undefined reference to `_glGetString'./Simple OpenGL Image Library/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x3ba): undefined reference to `_glGetString'./Simple OpenGL Image Library/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x3ed): undefined reference to `_glGetString'./Simple OpenGL Image Library/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x40e): undefined reference to `_glGetString'./Simple OpenGL Image Library/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x45a): more undefined references to `_glGetString' follow./Simple OpenGL Image Library/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x4cb): undefined reference to `_glXGetProcAddressARB'./Simple OpenGL Image Library/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x8af): undefined reference to `_glTexImage2D'./Simple OpenGL Image Library/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x9cd): undefined reference to `_glTexImage2D'./Simple OpenGL Image Library/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0xa23): undefined reference to `_glDeleteTextures'./Simple OpenGL Image Library/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0xaa3): undefined reference to `_glTexParameteri'./Simple OpenGL Image Library/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0xac3): undefined reference to `_glTexParameteri'./Simple OpenGL Image Library/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0xaed): undefined reference to `_glTexParameteri'./Simple OpenGL Image Library/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0xb0d): undefined reference to `_glTexParameteri'./Simple OpenGL Image Library/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0xb2d): undefined reference to `_glTexParameteri'./Simple OpenGL Image Library/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0xc2b): undefined reference to `_glGenTextures'./Simple OpenGL Image Library/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0xc65): undefined reference to `_glTexParameteri'./Simple OpenGL Image Library/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0xc85): undefined reference to `_glTexParameteri'./Simple OpenGL Image Library/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0xd09): undefined reference to `_glTexParameteri'./Simple OpenGL Image Library/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0xfb6): undefined reference to `_glGetIntegerv'./Simple OpenGL Image Library/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x1305): undefined reference to `_glTexImage2D'./Simple OpenGL Image Library/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x1465): undefined reference to `_glTexImage2D'./Simple OpenGL Image Library/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x14ad): undefined reference to `_glTexImage2D'./Simple OpenGL Image Library/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x14d4): undefined reference to `_glTexParameteri'./Simple OpenGL Image Library/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x14f1): undefined reference to `_glTexParameteri'./Simple OpenGL Image Library/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x151e): undefined reference to `_glTexParameteri'./Simple OpenGL Image Library/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x1531): undefined reference to `_glTexParameteri'./Simple OpenGL Image Library/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x157a): undefined reference to `_glTexParameteri'./Simple OpenGL Image Library/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x1594): more undefined references to `_glTexParameteri' follow./Simple OpenGL Image Library/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x1611): undefined reference to `_glGenTextures'./Simple OpenGL Image Library/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x1748): undefined reference to `_glTexImage2D'collect2: ld returned 1 exit statusmake: *** [flock_you.exe] Error 1


Edit: removed warnings related to my code
Advertisement
HI,

1) Congratulations on necro'ing a thread from 3 years ago...

2) gcc (including g++) on OS X uses frameworks, which contain headers and object code in one package. I dont know the full details, but there are various things for you to find online. Mostly they recommend g++ <your various files> -framework OpenGL -framework glut or similar.


Don't thank me, thank the moon's gravitation pull! Post in My Journal and help me to not procrastinate!
I probably should have rewritten the last line as:

However, when I attempt to compile the SOIL lib and then my game in cygwin, I get the following errors due to undefined references:

This is what compiling on Mac OS X looks like:
$ makeg++ -Wall -o game_name -I./Simple\ OpenGL\ Image\ Library/src drawable.cpp texture.cpp player.cpp character.cpp main.cpp map.cpp collideable.cpp state.cpp -L./Simple\ OpenGL\ Image\ Library/lib -framework OpenGL -framework GLUT -framework CoreFoundation -lSOIL$

It's very beautiful. But when compiling under cygwin as in my previous post, I seem to get a lot of undefined references to OpenGL library functions. My original code also uses some of the same function, but has no issue compiling them. What do I have to do so that it won't complain about the OpenGL code inside of the SOIL library?

I originally tried linking opengl when recompiling the library, but it said I couldn't link in OpenGL when making a static library.
So I managed to remove a whole bunch of the undefined references by changing the order in which I called the static libraries, e.g.:

$ makeg++ -Wall -o game_name.exe -I/usr/include/opengl -I/usr/include/w32api -I./Simple\ OpenGL\ Image\ Library/src drawable.cpp texture.cpp player.cpp character.cpp main.cpp map.cpp collideable.cpp state.cpp -L/usr/lib/w32api -L./Simple\ OpenGL\ Image\ Library/lib -lSOIL -lglut32 -lglu32 -lopengl32./Simple OpenGL Image Library/lib/libSOIL.a(stb_image_aug.o):stb_image_aug.c:(.text+0x6c1): undefined reference to `__assert'./Simple OpenGL Image Library/lib/libSOIL.a(stb_image_aug.o):stb_image_aug.c:(.text+0x939): undefined reference to `__assert'./Simple OpenGL Image Library/lib/libSOIL.a(stb_image_aug.o):stb_image_aug.c:(.text+0xc7a): undefined reference to `__assert'./Simple OpenGL Image Library/lib/libSOIL.a(stb_image_aug.o):stb_image_aug.c:(.text+0x2d44): undefined reference to `__assert'./Simple OpenGL Image Library/lib/libSOIL.a(stb_image_aug.o):stb_image_aug.c:(.text+0x2ee6): undefined reference to `__assert'./Simple OpenGL Image Library/lib/libSOIL.a(stb_image_aug.o):stb_image_aug.c:(.text+0x2fb5): more undefined references to `__assert' follow


Any ideas as to how to remove these?
Figured everything out now. In one of the stb files, you have to add a #define NDEBUG before the line #include <assert.h> so that asserts are turned off. So to recap, if you want to use SOIL in a project that's going to be compiled in cygwin, you need to make sure when you compile that the -lSOIL flag comes before the -lopengl32 flag and that you define NDEBUG before assert.h is included. Hope this helps anyone else who decides to use cygwin to compile.
Hi,

I would like to use SOIL with VS 2008, but I have a problem with the library.
File libSOIL.lib I copied to VC\lib and SOIL.h to VC\include and in VS 2008 I added libSOIL.lib to the Project Properties>Configuration Properties>Linker>Input>Additional Dependencies.

#include "stdafx.h"#include <gl\glut.h>#include "SOIL.h"int _tmain(int argc, _TCHAR* argv[]){	GLuint tex_2d = SOIL_load_OGL_texture	(		"bow.bmp",		SOIL_LOAD_AUTO,		SOIL_CREATE_NEW_ID,		SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT	);	return 0;}


This code ganeretes these errors:
Error 1 error LNK2019: unresolved external symbol __alloca referenced in function _stbi_zlib_decode_noheader_buffer libSOIL.lib
Error 2 error LNK2019: unresolved external symbol _sqrtf referenced in function _RGBE_to_RGBdivA2 libSOIL.lib

Please help!
I would like to ask about SOIL:

Can it flip sprites "horizontally" instead of "vertically"?

Just making sure, because it didn't say anything about horizontal flipping in this page. I'm really worried about it.

[Edited by - tom_mai78101 on May 11, 2010 3:15:42 AM]
You shouldn't need to flip an image horizontally with the loading library. You will probably have to use something else if you really need that functionality.
Thank you for this great library. I ripped out 2 pages of code from my old and clunky image loader (based on SDL_image) and replaced it with SOIL.

It compiled, linked and worked as expected on the first try! :)

Hi, I am working on redhat.
Can someone exactly tell me how to link the library.
I put libSOIL.a in /usr/lib folder and SOIL.h file in /usr/include folder.

I included this line in my C++ program #include <SOIL.h>

On compiling it gives the following errors:

/tmp/cc1dkSnQ.o(.text+0x166): In function `glutDisplay()':
: undefined reference to `SOIL_load_OGL_texture'
/tmp/cc1dkSnQ.o(.text+0x17d): In function `glutDisplay()':
: undefined reference to `SOIL_last_result'
collect2: ld returned 1 exit status

Can someone please tell me what's wrong?

This topic is closed to new replies.

Advertisement