I specifically want to add stb_image_write.h to my project, but I am getting "multiple definition"errors when compiling using CMake.
I include stb_image_write.h into one header file called "screen.h" and the includes are as followed:
#include <SDL2/SDL.h>
#include <vector>
#include "float3.h"
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "stb_image_write.h"
I then include this header into the cpp file as followed:
#include "screen.h"
This is my CMake:
cmake_minimum_required(VERSION 3.8)
project(YAPT)
find_package(SDL2 REQUIRED)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -lSDL")
if(OPENMP_FOUND)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
endif()
set(CMAKE_CXX_FLAGS "-fopenmp")
include_directories(SYSTEM ${OpenMP_INCLUDE_PATH})
include_directories("${PROJECT_BINARY_DIR}")
link_directories("${PROJECT_BINARY_DIR}")
file(GLOB SOURCE_FILES "src/*.cpp")
file(GLOB HEADER_FILES "src/*.h")
add_executable(YAPT ${SOURCE_FILES} ${HEADER_FILES})
target_link_libraries(YAPT SDL2main SDL2)
The file location is in the same directory as CMakeLists.txt but I have also tried it inside the /src folder too with no luck.