I do not understand how to get rid of LNK2005 error when building a program in MSVC 2019 which uses boost 1.80 spirit. I tried to play with several examples from spirit qi and add them to the same project/solution. The problem appears in 2 cpp files.
I reduced to the minimum reproducible example and found that the culprit is
#include <boost/phoenix/stl.hpp>
In the project I have 2 cpp files (Test3 and Test6) containing only the above include line and when building the project, there are errors about 10 symbols with double definition.
The first and last error are:
Severity Code Description Project File Line Suppression State
Error "struct boost::phoenix::actor<struct boost::proto::exprns_::basic_expr<struct boost::phoenix::tag::get_with_idx,struct boost::proto::argsns_::list2<struct boost::proto::exprns_::basic_expr<struct boost::proto::tagns_::tag::terminal,struct boost::proto::argsns_::term<struct boost::phoenix::tuple_detail::idx_wrap<0> >,0>,struct boost::phoenix::actor<struct boost::proto::exprns_::basic_expr<struct boost::proto::tagns_::tag::terminal,struct boost::proto::argsns_::term<struct boost::phoenix::argument<1> >,0> > >,2> > boost::phoenix::placeholders::uarg1" (?uarg1@placeholders@phoenix@boost@@3U?$actor@U?$basic_expr@Uget_with_idx@tag@phoenix@boost@@U?$list2@U?$basic_expr@Uterminal@tag@tagns_@proto@boost@@U?$term@U?$idx_wrap@$0A@@tuple_detail@phoenix@boost@@@argsns_@45@$0A@@exprns_@proto@boost@@U?$actor@U?$basic_expr@Uterminal@tag@tagns_@proto@boost@@U?$term@U?$argument@$00@phoenix@boost@@@argsns_@45@$0A@@exprns_@proto@boost@@@phoenix@4@@argsns_@proto@4@$01@exprns_@proto@boost@@@23@A) already defined in Test3.obj BoostTests C:\Users\Claudiu\BoostTests\Debug\Test6.obj 1
...
Error LNK1169 one or more multiply defined symbols found BoostTests C:\Users\Claudiu\BoostTests\BoostTest.exe 1
The link error from above contradicts the header philosophy of boost and documentation of Phoenix which states: "The library has grown from the original Phoenix but still comprises only header files. There are no object files to link against.". In theory a header only library shall not define any variables in order to allow the header to be included in any number of cpp file is needed.
Other files from the project uses other phoenix includes without giving any error.
If only one of the cpp file is including the header file then the build ends without errors.
If you make a solution for every example then building the project works without errors but this is unacceptable.
Update: I managed to reproduce it not only with MSVC compilers but also with gcc. See project at https://godbolt.org/z/74c1c5qoe
Reverting this commit (and thereby removing tuple support) fixes the errors.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With