我正在使用DevIL编写一个C++ OpenGL项目,在尝试加载用作纹理的图像时遇到编译时错误。
到目前为止,我有这个
//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);
}这向我展示了一个错误:error C2110: '+' : cannot add two pointers
如果我将filename的声明更改为string filename = "back.bmp";,将if语句更改为
if (!ilLoadImage(const_cast<char*>(filename.c_str())))我得到这个链接器错误error LNK1104: cannot open file 'DevIL.libkernel32.lib'
我确信我已经将所有的DevIL文件放在了它们需要的位置,并在Project->Properties->Linker->Input->Additional依赖项中添加了依赖项。
发布于 2011-04-16 21:36:04
通过确保添加的是C++字符串而不是C字符串来修复编译错误
throw runtime_error(std::string("Unable to load image") +filename);通过在附加依赖项中的库之间放置一个空格来修复链接错误。
另外,如果你必须使用const_cast,你很可能做错了。
ILboolean ilLoadImage(const char *filename);不需要强制转换为char *来传递.c_str() - .c_str()返回const char *
https://stackoverflow.com/questions/5686814
复制相似问题