DevIL and OpenGL in C++
DevIL and OpenGL in C++
我正在使用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 dependencies中添加了依赖项。
通过确保添加 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 *
相关文章:
- netcat command in c++
- Difference in displaying cv2 Mat
- C++ MFC Libraries in Travis CI
- 如何在OpenSSL中从configuration.h.in获取configuration.h
- 创建具有 new in 函数和"this is nullptr"异常的对象
- IN, OUT, INOUT Parameters
- 应用程序崩溃并显示"symbol _ZdlPvm, version Qt_5 not defined in file libQt5Core.so.5 with link time reference"
- 有人安装"IITB Simplecpp in mac"吗?
- 从 C 样式字符串中删除子字符串 "in place" 在C++代码中
- 如何修复"error: ‘_1’ was not declared in this scope"?
- Softmax Implementation in C++
- 将 out/in out 参数与 if/switch 的 init 语句一起使用
- IF-nesting in c++
- Gurobi GRBModel and GRBmodel in C++
- Tensorflow Hub in C++
- Centos7 g++ "to_string is not in a member of std"
- InitializeCriticalSectionEx Not Located In KERNEL32.Dll
- 将 lambda 表达式传递给 std::function in C++
- @CPPFLAGS@在 Makefile.in 中意味着什么?
- std::async from std::async in windows xp