使用 tinygltf 和 sfml 实现机顶盒图像

STB Image Implementation with tinygltf and sfml

我在我的项目中包括了 tinygltf 和 sfml。当我将 tinygltf 包含在这些选项中时:

#define TINYGLTF_IMPLEMENTATION
#define STB_IMAGE_IMPLEMENTATION
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include <tiny_gltf.h>

我遇到多个定义错误:

/usr/bin/ld.gold: error: sfml/lib/libsfml-graphics-s.a(ImageLoader.cpp.o): multiple definition of 'stbi_write_jpg'
/usr/bin/ld.gold: _objs/client_lib/loader.pic.o: previous definition here

这只是错误的一小部分,但对于大多数 stb 函数,都存在类似的错误。所以我试图通过像这样包含 tinygltf 来解决这个问题:

#define TINYGLTF_IMPLEMENTATION
#include <tiny_gltf.h>

但是,现在只有一个奇异错误:

_objs/client_lib/loader.pic.o:loader.cpp:function tinygltf::LoadImageData(tinygltf::Image*, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, int, int, unsigned char const*, int, void*): error: undefined reference to 'stbi_is_16_bit_from_memory'

这两个库似乎依赖于略有不同的 stb 版本。有什么办法可以解决这个问题吗?

我使用的是 tinygltf 2.2.0 版和 sfml 2.5.1 版。

由于您静态链接 SFML,因此您将 SFML 的所有符号集成到您的应用程序中,包括 STB 符号。

我在这里看到两种不同的解决方案,也许还有更多:

  • 更新 SFML extlibs/ 目录中的 STB header 并重建 SFML
  • Link SFML 是动态的,因此您的应用程序看不到 SFML STB 符号