Sas*_*kia 0 c++ boost header lnk2005
我有一个大项目。
在N.cpp我需要使用boost::filesystem::exists(path)检查路径是否有效。
为此,我包括 <boost/filesystem.hpp>
我收到以下错误:
Error 2 error LNK2005: "public: enum boost::filesystem::file_type __cdecl boost::filesystem::file_status::type(void)const " (?type@file_status@filesystem@boost@@QEBA?AW4file_type@23@XZ) already defined in N.obj D:\MProject\DA\boost_filesystem-vc100-mt-gd-1_53.lib(boost_filesystem-vc100-mt-gd-1_53.dll) DA
Error 1 error LNK2005: "public: __cdecl boost::filesystem::path::~path(void)" (??1path@filesystem@boost@@QEAA@XZ) already defined in N.obj D:\MProject\DAboost_filesystem-vc100-mt-gd-1_53.lib(boost_filesystem-vc100-mt-gd-1_53.dll) DA
Error 3 error LNK1104: cannot open file 'libboost_filesystem-vc100-mt-gd-1_53.lib' D:\MProject\DA\LINK DA
Run Code Online (Sandbox Code Playgroud)
如果不包含头文件,则会得到:
Error 2 error C3861: 'exists': identifier not found D:\MProject\DA\ThirdParty\N.cpp 108 1 DA
Error 1 error C2653: 'boost' : is not a class or namespace name D:\MProject\DA\ThirdParty\N.cpp 108 1 DA
Run Code Online (Sandbox Code Playgroud)
什么是正确的使用方法,boost::filesystem::exists以便整个过程可以编译?
#include <boost/filesystem.hpp>
.....
CHECK( boost::filesystem::exists(*i), std::string("file ").append(*i).append(" does not exist").c_str() );
.....
Run Code Online (Sandbox Code Playgroud)
我通过添加到N.cpp解决了这个问题:
#ifndef BOOST_ALL_DYN_LINK
# define BOOST_ALL_DYN_LINK
#endif
#include <boost/filesystem.hpp>
Run Code Online (Sandbox Code Playgroud)