stb_ds multiple definition error #1464
-
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
The error messages say it's already defined in bus.c Read this line of comment very carefully: |
Beta Was this translation helpful? Give feedback.
-
??? You can put the include in as many C or H files as you like. Just only put the define in one C file. Exactly one, no more, no less. |
Beta Was this translation helpful? Give feedback.
-
@Aragami1408 Here is what I did. My project structure: $ ll
total 52
drwxrwxr-x 2 lai lai 4096 Mär 25 09:06 ./
drwxrwxr-x 5 lai lai 4096 Mär 25 09:06 ../
-rw-rw-r-- 1 lai lai 1498 Mär 25 09:03 CMakeLists.txt
-rw-rw-r-- 1 lai lai 132 Mär 25 08:54 define_stb_image.cpp
-rw-rw-r-- 1 lai lai 9556 Mär 25 09:56 image_eigen.cpp
-rw-rw-r-- 1 lai lai 927 Mär 25 09:06 image_eigen.hpp
-rw-rw-r-- 1 lai lai 11661 Mär 25 10:16 image_xtensor.cpp
-rw-rw-r-- 1 lai lai 994 Mär 25 09:58 image_xtensor.hpp Both $ cat define_stb_image.cpp
#define STB_IMAGE_IMPLEMENTATION
#include <stb/stb_image.h>
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include <stb/stb_image_write.h> and in add_library(stb_library STATIC)
target_sources(stb_library PUBLIC define_stb_image.cpp)
target_include_directories(stb_library PUBLIC ${CMAKE_SOURCE_DIR}/extern)
add_library(image_eigen STATIC)
target_link_libraries (image_eigen Eigen3::Eigen stb_library)
target_sources(image_eigen PUBLIC image_eigen.cpp)
add_library(image_xtensor STATIC)
target_link_libraries (image_xtensor xtensor xtensor::optimize xtensor::use_xsimd stb_library)
target_sources(image_xtensor PUBLIC image_xtensor.cpp) Now I can include stb library in both
|
Beta Was this translation helpful? Give feedback.
-
Doing it that way works, but it's not necessary. All you have to do is put the IMPLEMENTATION #define in one and only one C/CPP file. |
Beta Was this translation helpful? Give feedback.
???
You can put the include in as many C or H files as you like. Just only put the define in one C file. Exactly one, no more, no less.