我需要为学生项目使用 OpenGL 编写一个小游戏。我还必须使用 CMake 来完成这个项目。我包含了用于导入纹理的 stb_image.c。
我将以下几行添加到我的 CMakeList.txt 中
include_directories(${CMAKE_SOURCE_DIR}/../extern/stb_image)
link_directories(${CMAKE_SOURCE_DIR}/../extern/stb_image)
Run Code Online (Sandbox Code Playgroud)
并将 stb_image.h 包含到我的项目文件中。代码编译没有错误。现在我尝试使用以下代码将纹理导入到我的项目中。
#include "stb_image.h"
int x, y, n;
unsigned char *data = stbi_load("testTexture.png" , &x, &y, &n, 0);
Run Code Online (Sandbox Code Playgroud)
如果我尝试使用“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] …Run Code Online (Sandbox Code Playgroud)