[英]Including the Boost filesystem header
I have a big project. 我有一个大项目。
In N.cpp
I need to use boost::filesystem::exists(path)
to check if the path is valid. 在
N.cpp
我需要使用boost::filesystem::exists(path)
来检查路径是否有效。
For that, I include <boost/filesystem.hpp>
为此,我包括
<boost/filesystem.hpp>
I get the following error: 我收到以下错误:
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
If I do not include the header file, I get: 如果不包含头文件,则会得到:
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
What is the right way to use boost::filesystem::exists
so that the whole thing would compile? 什么是使用
boost::filesystem::exists
以便整体编译的正确方法?
#include <boost/filesystem.hpp>
.....
CHECK( boost::filesystem::exists(*i), std::string("file ").append(*i).append(" does not exist").c_str() );
.....
I solved the problem by adding to N.cpp: 我通过添加到N.cpp解决了这个问题:
#ifndef BOOST_ALL_DYN_LINK
# define BOOST_ALL_DYN_LINK
#endif
#include <boost/filesystem.hpp>
If you want to use boost::filesystem
you have to include the header file (directly or indirectly via other includes). 如果要使用
boost::filesystem
,则必须包含头文件(直接或通过其他include间接)。
The first three errors are linker errors. 前三个错误是链接器错误。 Some parts of Boost are header-only, ie you don't have to compile Boost when you want to use them.
Boost的某些部分仅是标头,即,当您要使用它们时不必编译Boost。 Unfortunately filesystem isn't one of them.
不幸的是文件系统不是其中之一。 That means you have to compile Boost like described here .
这意味着您必须像这里描述的那样编译Boost。 Afterwards you have to tell your linker where it can find the binaries you just created and it should compile well (if you didn't do any other mistakes ;-) ).
然后,您必须告诉链接程序在哪里可以找到您刚刚创建的二进制文件,并且应该可以正确编译(如果您没有犯其他错误;-)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.