-1
我需要用OpenGL編寫一個小遊戲給學生項目。我也必須爲這個項目使用CMake。我包含了用於導入紋理的stb_image.c。包括stb_image到CMake的OpenGL項目
我包括以下幾行我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 2
inits.cc是項目文件和loadObjectsAndTextures()是調用stbi_load方法()。
我真的不知道什麼崩潰在這裏。我把CMake的文件鏈接錯了嗎,我的函數調用是錯誤的還是我在這裏甚至沒有看到的東西?你能給我任何建議,我可以開始解決這個問題嗎?我嘗試了幾個小時來閱讀CMake的教程和stb_image的Documentation。紋理位於我的項目文件的同一目錄中,並且位於與stb_image.c相同的目錄中。