2
votes

I am writing a C++ OpenGL project using DevIL and I am getting compile-time errors while trying to work out how to load an image to use as a texture.

So far I have this

//Declarations
const char* filename = "back.bmp";
ILboolean ilLoadImage(const char *filename);

ILuint image;
ilGenImages(1, &image);
ilBindImage(image);

//Load the image
if (!ilLoadImage(filename))
{
throw runtime_error("Unable to load image" +filename);
}

which presents me with the error: error C2110: '+' : cannot add two pointers

if I change the declaration of filename to string filename = "back.bmp"; and the if statement to

if (!ilLoadImage(const_cast<char*>(filename.c_str())))

I get this linker error error LNK1104: cannot open file 'DevIL.libkernel32.lib'

I am certain that I have placed all the DevIL files where they need to be and added the dependencies in Project->Properties->Linker->Input->Additional Dependencies.

1

1 Answers

2
votes

Fix the compile error by ensuring you add C++ strings not C strings

throw runtime_error(std::string("Unable to load image") +filename);

Fix the link error by putting a space in between the libs in Additional Dependencies.

Also, if you have to use const_cast, odds are you're doing it wrong.

ILboolean ilLoadImage(const char *filename);

You don't need to cast to char * in order to pass .c_str() - .c_str() returns a const char *