首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >C++中的DevIL和OpenGL

C++中的DevIL和OpenGL
EN

Stack Overflow用户
提问于 2011-04-16 21:31:15
回答 1查看 1.5K关注 0票数 2

我正在使用DevIL编写一个C++ OpenGL项目,在尝试加载用作纹理的图像时遇到编译时错误。

到目前为止,我有这个

代码语言:javascript
复制
//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语句更改为

代码语言:javascript
复制
if (!ilLoadImage(const_cast<char*>(filename.c_str())))

我得到这个链接器错误error LNK1104: cannot open file 'DevIL.libkernel32.lib'

我确信我已经将所有的DevIL文件放在了它们需要的位置,并在Project->Properties->Linker->Input->Additional依赖项中添加了依赖项。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-04-16 21:36:04

通过确保添加的是C++字符串而不是C字符串来修复编译错误

代码语言:javascript
复制
throw runtime_error(std::string("Unable to load image") +filename);

通过在附加依赖项中的库之间放置一个空格来修复链接错误。

另外,如果你必须使用const_cast,你很可能做错了。

代码语言:javascript
复制
ILboolean ilLoadImage(const char *filename);

不需要强制转换为char *来传递.c_str() - .c_str()返回const char *

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5686814

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档