How to solve duplicated symbol problems in C++
Problem
When compiling a program which sources sharing a same headers, for example, SWYAKL, there is possibility that error of duplicated symbol will appear during link stage.
For me, this problem is because SWYAKL is a header-only library, C++ compiler's preprocessor will expand headers to every source files include this header, so a function named yakl::yakl_std_wrapper::round
had been added to top of every source files, and caused this error.
Solution
Duplicated symbol error cannot be avoid by using header guard or #pragma once
, because these function only tell compiler to compiler your source once, but will take no effect on avoid duplicated symbols be generated by compiler.
To solve this problem, the easiest way is change this function into an inline function.
1 |
|