When I try to use Assimp together with stb it says that some functions are already defined and it will not link.
CMakeLists.txt
cmake_minimum_required(VERSION 3.20)
project(TestProject)
add_executable(TestProject "main.cpp")
set(BUILD_SHARED_LIBS OFF)
add_subdirectory("vendor/assimp")
target_include_directories(TestProject PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/vendor/stb")
target_include_directories(TestProject PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/vendor/assimp/include")
target_include_directories(TestProject PUBLIC "${CMAKE_CURRENT_BINARY_DIR}/vendor/assimp/include")
target_link_libraries(TestProject PUBLIC assimp)
main.cpp
#include <iostream>
#include "assimp/Importer.hpp"
#include "assimp/scene.h"
#include "assimp/postprocess.h"
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
int main(){
std::cout << "Hello World" << std::endl;
int width, height, nrChannels;
uint8_t* data = stbi_load("image.jpg", &width, &height, &nrChannels, 0);
Assimp::Importer importer;
stbi_image_free(data);
std::cin.get();
}
This is the output I got from this. It seems like a few functions from the stb file could not be linked correctly.
4>assimp-vc142-mtd.lib(PbrtExporter.obj) : error LNK2005: stbi_load_from_memory already defined in main.obj
4>assimp-vc142-mtd.lib(PbrtExporter.obj) : error LNK2005: stbi_load_from_callbacks already defined in main.obj
4>assimp-vc142-mtd.lib(PbrtExporter.obj) : error LNK2005: stbi_load already defined in main.obj
4>assimp-vc142-mtd.lib(PbrtExporter.obj) : error LNK2005: stbi_load_from_file already defined in main.obj
4>assimp-vc142-mtd.lib(PbrtExporter.obj) : error LNK2005: stbi_load_gif_from_memory already defined in main.obj
4>assimp-vc142-mtd.lib(PbrtExporter.obj) : error LNK2005: stbi_load_16_from_memory already defined in main.obj
4>assimp-vc142-mtd.lib(PbrtExporter.obj) : error LNK2005: stbi_load_16_from_callbacks already defined in main.obj
4>assimp-vc142-mtd.lib(PbrtExporter.obj) : error LNK2005: stbi_load_16 already defined in main.obj
4>assimp-vc142-mtd.lib(PbrtExporter.obj) : error LNK2005: stbi_load_from_file_16 already defined in main.obj
4>assimp-vc142-mtd.lib(PbrtExporter.obj) : error LNK2005: stbi_loadf_from_memory already defined in main.obj
4>assimp-vc142-mtd.lib(PbrtExporter.obj) : error LNK2005: stbi_loadf_from_callbacks already defined in main.obj
4>assimp-vc142-mtd.lib(PbrtExporter.obj) : error LNK2005: stbi_loadf already defined in main.obj
...
I'm building from the source files.