yosh-matsuda / cpp-yyjson

Ultra-fast and intuitive C++ JSON reader/writer with yyjson backend
MIT License
63 stars 6 forks source link

Linking error when including cpp_yyjson.hpp in 2(or above) .cpp files #1

Closed decades42 closed 1 year ago

decades42 commented 1 year ago

Error:

``` /usr/bin/ld: CMakeFiles/server.dir/src/server/processor.cpp.o: in function `yyjson::reader::value::as_array() &&': processor.cpp:(.text+0x0): multiple definition of `yyjson::reader::value::as_array() &&'; CMakeFiles/server.dir/src/config.cpp.o:config.cpp:(.text+0x0): first defined here /usr/bin/ld: CMakeFiles/server.dir/src/server/processor.cpp.o: in function `yyjson::reader::value::as_object() &&': processor.cpp:(.text+0x78): multiple definition of `yyjson::reader::value::as_object() &&'; CMakeFiles/server.dir/src/config.cpp.o:config.cpp:(.text+0x78): first defined here /usr/bin/ld: CMakeFiles/server.dir/src/server/processor.cpp.o: in function `yyjson::reader::read(char*, unsigned long, yyjson::ReadFlag)': processor.cpp:(.text+0xef): multiple definition of `yyjson::reader::read(char*, unsigned long, yyjson::ReadFlag)'; CMakeFiles/server.dir/src/config.cpp.o:config.cpp:(.text+0xef): first defined here /usr/bin/ld: CMakeFiles/server.dir/src/server/processor.cpp.o: in function `yyjson::reader::read(char const*, unsigned long, yyjson::ReadFlag)': processor.cpp:(.text+0x2d9): multiple definition of `yyjson::reader::read(char const*, unsigned long, yyjson::ReadFlag)'; CMakeFiles/server.dir/src/config.cpp.o:config.cpp:(.text+0x2d9): first defined here /usr/bin/ld: CMakeFiles/server.dir/src/server/processor.cpp.o: in function `yyjson::reader::read(std::__cxx11::basic_string, std::allocator >&, unsigned long, yyjson::ReadFlag)': processor.cpp:(.text+0x3a5): multiple definition of `yyjson::reader::read(std::__cxx11::basic_string, std::allocator >&, unsigned long, yyjson::ReadFlag)'; CMakeFiles/server.dir/src/config.cpp.o:config.cpp:(.text+0x3a5): first defined here /usr/bin/ld: CMakeFiles/server.dir/src/server/processor.cpp.o: in function `yyjson::reader::read(std::__cxx11::basic_string, std::allocator > const&, unsigned long, yyjson::ReadFlag)': processor.cpp:(.text+0x506): multiple definition of `yyjson::reader::read(std::__cxx11::basic_string, std::allocator > const&, unsigned long, yyjson::ReadFlag)'; CMakeFiles/server.dir/src/config.cpp.o:config.cpp:(.text+0x506): first defined here /usr/bin/ld: CMakeFiles/server.dir/src/server/processor.cpp.o: in function `yyjson::reader::read(std::basic_string_view >, unsigned long, yyjson::ReadFlag)': processor.cpp:(.text+0x5ec): multiple definition of `yyjson::reader::read(std::basic_string_view >, unsigned long, yyjson::ReadFlag)'; CMakeFiles/server.dir/src/config.cpp.o:config.cpp:(.text+0x5ec): first defined here /usr/bin/ld: CMakeFiles/server.dir/src/server/processor.cpp.o: in function `yyjson::reader::read(char*, yyjson::ReadFlag)': processor.cpp:(.text+0x6e0): multiple definition of `yyjson::reader::read(char*, yyjson::ReadFlag)'; CMakeFiles/server.dir/src/config.cpp.o:config.cpp:(.text+0x6e0): first defined here /usr/bin/ld: CMakeFiles/server.dir/src/server/processor.cpp.o: in function `yyjson::reader::read(std::__cxx11::basic_string, std::allocator >&, yyjson::ReadFlag)': processor.cpp:(.text+0x743): multiple definition of `yyjson::reader::read(std::__cxx11::basic_string, std::allocator >&, yyjson::ReadFlag)'; CMakeFiles/server.dir/src/config.cpp.o:config.cpp:(.text+0x743): first defined here /usr/bin/ld: CMakeFiles/server.dir/src/server/processor.cpp.o: in function `yyjson::reader::read(std::__cxx11::basic_string, std::allocator > const&, yyjson::ReadFlag)': processor.cpp:(.text+0x7b6): multiple definition of `yyjson::reader::read(std::__cxx11::basic_string, std::allocator > const&, yyjson::ReadFlag)'; CMakeFiles/server.dir/src/config.cpp.o:config.cpp:(.text+0x7b6): first defined here /usr/bin/ld: CMakeFiles/server.dir/src/server/processor.cpp.o: in function `yyjson::reader::read(std::basic_string_view >, yyjson::ReadFlag)': processor.cpp:(.text+0x829): multiple definition of `yyjson::reader::read(std::basic_string_view >, yyjson::ReadFlag)'; CMakeFiles/server.dir/src/config.cpp.o:config.cpp:(.text+0x829): first defined here /usr/bin/ld: CMakeFiles/server.dir/src/server/processor.cpp.o: in function `yyjson::reader::read(char const*, yyjson::ReadFlag)': processor.cpp:(.text+0x8a9): multiple definition of `yyjson::reader::read(char const*, yyjson::ReadFlag)'; CMakeFiles/server.dir/src/config.cpp.o:config.cpp:(.text+0x8a9): first defined here collect2: error: ld returned 1 exit status make[2]: *** [CMakeFiles/server.dir/build.make:186: server] Error 1 make[1]: *** [CMakeFiles/Makefile2:100: CMakeFiles/server.dir/all] Error 2 make: *** [Makefile:91: all] Error 2 ```

gcc version is 12.2.1 20230201

yosh-matsuda commented 1 year ago

@decades42 Thanks for the report. It's fixed c0af541db7f3f2b188a2e604268f0e90b19e40c2.