相关疑难解决方法(0)

无法使用Boost.Filesystem链接程序

我正在尝试运行程序,在Ubuntu 12.10上使用boost :: filesystem的示例代码,但它不想构建.

#include <iostream>
#include <boost/filesystem.hpp>
using namespace boost::filesystem;
using namespace std;

void fun(const string& dirPath);
int main()
{
    fun("/home");
    return 0;
}

void fun(const string& dirPath)
{
    path p (dirPath); 

    if (exists(p))  
    {
        if (is_regular_file(p))   
            cout << p << " size is " << file_size(p) << '\n';

        else if (is_directory(p))    
            cout << p << "is a directory\n";

        else
            cout << p << "exists, but is neither a regular file nor a directory\n";
    }
    else
        cout << p …
Run Code Online (Sandbox Code Playgroud)

c++ boost cmake

20
推荐指数
2
解决办法
2万
查看次数

在c ++ 11中,boost :: filesystem :: copy_file()缺少符号

如果在没有 C++ 11支持的情况下编译Boost,则boost::filesystem使用模拟的作用域枚举器.如果您随后使用此构建的Boost并在具有 C++ 11支持的项目中使用它,则最终会丢失符号,因为声明boost::filesystem::copy_file()已更改.

有一个简单的解决方法:

# if __cplusplus >= 201103L
#   define NO_SCOPED_ENUMS
# endif
# ifdef NO_SCOPED_ENUMS
#   if BOOST_VERSION < 105000
#     ifndef BOOST_NO_SCOPED_ENUMS
#       define BOOST_NO_SCOPED_ENUMS
#       define REMOVE
#     endif
#   else
#     ifndef BOOST_NO_CXX11_SCOPED_ENUMS
#       define BOOST_NO_CXX11_SCOPED_ENUMS
#       define REMOVE
#     endif
#   endif
# endif
# include "boost/filesystem.hpp"
# if defined(NO_SCOPED_ENUMS) && defined(REMOVE)
#   undef REMOVE
#   if BOOST_VERSION < 105000
#     undef BOOST_NO_SCOPED_ENUMS
# …
Run Code Online (Sandbox Code Playgroud)

boost c++11

5
推荐指数
1
解决办法
1821
查看次数

标签 统计

boost ×2

c++ ×1

c++11 ×1

cmake ×1