veselink1 / refl-cpp

Static reflection for C++17 (compile-time enumeration, attributes, proxies, overloads, template functions, metaprogramming).
https://veselink1.github.io/refl-cpp/md__introduction.html
MIT License
1.06k stars 77 forks source link

Multiple definition of `refl::runtime::detail::next_depth(int)' #33

Closed james-conrad closed 4 years ago

james-conrad commented 4 years ago

When including refl.hpp from more than one source file using gcc 7.5.0, the compiler complains that refl::runtime::detail::next_depth(int) is defined multiple times.

g++ -I./src -MMD -MP --std=c++17 -c src/Effect.cpp -o build/./src/Effect.cpp.o
g++ -I./src -MMD -MP --std=c++17 -c src/main.cpp -o build/./src/main.cpp.o
g++ -I./src -MMD -MP --std=c++17 -c src/Object.cpp -o build/./src/Object.cpp.o
g++ ./build/./src/Effect.cpp.o ./build/./src/main.cpp.o ./build/./src/Object.cpp.o -o build/a.out
./build/./src/main.cpp.o: In function `refl::runtime::detail::next_depth(int)':
main.cpp:(.text+0x0): multiple definition of `refl::runtime::detail::next_depth(int)'
./build/./src/Effect.cpp.o:Effect.cpp:(.text+0x0): first defined here
./build/./src/Object.cpp.o: In function `refl::runtime::detail::next_depth(int)':
Object.cpp:(.text+0x0): multiple definition of `refl::runtime::detail::next_depth(int)'
./build/./src/Effect.cpp.o:Effect.cpp:(.text+0x0): first defined here
collect2: error: ld returned 1 exit status
Makefile:17: recipe for target 'build/a.out' failed
make: *** [build/a.out] Error 1

Moving the function into an anonymous namespace or declaring it static (both of which force internal linkage) resolves the issue.

veselink1 commented 4 years ago

Thanks! Merged in c23c2bb.