我需要编写一个学生项目与OpenGL的小游戏。我还必须在这个项目中使用CMake。我包含了用于导入纹理的stb_image.c。
我在CMakeList.txt中包含了以下几行
include_directories(${CMAKE_SOURCE_DIR}/../extern/stb_image)
link_directories(${CMAKE_SOURCE_DIR}/../extern/stb_image) 并将stb_image.h包含到我的项目文件中。代码编译时没有错误。现在,我尝试使用以下代码将纹理导入到我的项目中。
#include "stb_image.h"
int x, y, n;
unsigned char *data = stbi_load("testTexture.png" , &x, &y, &n, 0);如果我尝试使用"make“命令编译项目,我会得到以下错误:
Linking CXX executable /Users/.../Documents/.../.../.../binaries/basic-texturing
Undefined symbols for architecture x86_64:
"_stbi_load", referenced from:
loadObjectsAndTextures() in inits.cc.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [/Users/.../Documents/.../.../.../binaries/basic-texturing] Error 1
make[1]: *** [CMakeFiles/basic-texturing.dir/all] Error 2
make: *** [all] Error 2inits.cc是项目文件,loadObjectsAndTextures()是调用stbi_load()的方法。
我真的不知道这里出了什么问题。我是否用CMake链接了错误的文件,是我的函数调用错误,还是我在这里看不到的东西。你能给我一些建议,让我从哪里开始解决这个问题吗?我花了几个小时通读CMake和stb_image版Documentation的教程。纹理位于我的项目文件的相同目录中,也与stb_image.c位于相同的目录中。
发布于 2018-03-25 08:39:28
嘿,你只需要在include上面添加这个。
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h发布于 2014-01-28 07:30:23
在我看来,您正在尝试链接一个不是为64位系统编译的stb_image版本。您确定您正在为您的系统使用正确的库文件吗?
https://stackoverflow.com/questions/21393675
复制相似问题