Boost编译错误?

3

我正在尝试构建这个程序:

#include "stdafx.h"
#include <boost/interprocess/shared_memory_object.hpp>
#include <boost/interprocess/file_mapping.hpp>
#include <boost/interprocess/mapped_region.hpp>

using namespace std;

int main()
{
    using boost::interprocess;

    // Create the file mapping
    file_mapping fm("input.dat", read_only);
    // Map the file in memory
    mapped_region region(fm, read_only);
    // Get the address where the file has been mapped
    float * addr = (float *)region.get_address();
    std::size_t elements = region.get_size() / sizeof(float);
}

但是我遇到了两个问题,主要的问题是我得到了以下错误信息:
1>tasker.cpp(98): error C2873: 'boost::interprocess' : symbol cannot be used in a using-declaration
1>tasker.cpp(101): error C2065: 'file_mapping' : undeclared identifier
1>tasker.cpp(101): error C2146: syntax error : missing ';' before identifier 'fm'
1>tasker.cpp(101): error C2065: 'read_only' : undeclared identifier
1>tasker.cpp(101): error C3861: 'fm': identifier not found
1>tasker.cpp(103): error C2065: 'mapped_region' : undeclared identifier
1>tasker.cpp(103): error C2146: syntax error : missing ';' before identifier 'region'
1>tasker.cpp(103): error C2065: 'fm' : undeclared identifier
1>tasker.cpp(103): error C2065: 'read_only' : undeclared identifier
1>tasker.cpp(103): error C3861: 'region': identifier not found
1>tasker.cpp(105): error C2065: 'region' : undeclared identifier
1>tasker.cpp(105): error C2228: left of '.get_address' must have class/struct/union
1>          type is 'unknown-type'
1>tasker.cpp(106): error C2065: 'region' : undeclared identifier
1>tasker.cpp(106): error C2228: left of '.get_size' must have class/struct/union
1>          type is 'unknown-type'

对于 #include <boost/interprocess/mapped_region.hpp>,我得到了以下结果

1>C:\Users\Mike\Documents\boost_1_55_0\boost/intrusive/detail/has_member_function_callable_with.hpp(200): error C2228: left of '.select_on_container_copy_construction' must have class/struct/union
1>          type is 'boost::move_detail::add_rvalue_reference<U>::type'
1>          C:\Users\Mike\Documents\boost_1_55_0\boost/intrusive/detail/has_member_function_callable_with.hpp(276) : see reference to class template instantiation 'boost::container::container_detail::has_member_function_callable_with_select_on_container_copy_construction_impl<Fun,true,>' being compiled
1>          with
1>          [
1>              Fun=std::allocator<std::pair<const boost::interprocess::ipcdetail::sync_id *const ,boost::unordered::iterator_detail::iterator<boost::unordered::detail::ptr_node<std::pair<const boost::interprocess::ipcdetail::sync_id,void *>>>>>
1>          ]
1>          C:\Users\Mike\Documents\boost_1_55_0\boost/container/allocator_traits.hpp(262) : see reference to class template instantiation 'boost::container::container_detail::has_member_function_callable_with_select_on_container_copy_construction<const Alloc,>' being compiled
1>          with
1>          [
1>              Alloc=std::allocator<std::pair<const boost::interprocess::ipcdetail::sync_id *const ,boost::unordered::iterator_detail::iterator<boost::unordered::detail::ptr_node<std::pair<const boost::interprocess::ipcdetail::sync_id,void *>>>>>
1>          ]
1>          C:\Users\Mike\Documents\boost_1_55_0\boost/container/detail/tree.hpp(217) : see reference to class template instantiation 'boost::container::allocator_traits<A>' being compiled
1>          with
1>          [
1>              A=std::allocator<std::pair<const boost::interprocess::ipcdetail::sync_id *const ,boost::unordered::iterator_detail::iterator<boost::unordered::detail::ptr_node<std::pair<const boost::interprocess::ipcdetail::sync_id,void *>>>>>
1>          ]
1>          C:\Users\Mike\Documents\boost_1_55_0\boost/container/detail/tree.hpp(246) : see reference to class template instantiation 'boost::container::container_detail::intrusive_rbtree_type<A,boost::container::container_detail::tree_value_compare<Key,std::pair<const Key,T>,Compare,boost::container::container_detail::select1st<std::pair<const Key,T>>>>' being compiled
1>          with
1>          [
1>              A=std::allocator<std::pair<const boost::interprocess::ipcdetail::sync_id *const ,boost::unordered::iterator_detail::iterator<boost::unordered::detail::ptr_node<std::pair<const boost::interprocess::ipcdetail::sync_id,void *>>>>>
1>  ,            Key=const boost::interprocess::ipcdetail::sync_id *
1>  ,            T=boost::unordered::iterator_detail::iterator<boost::unordered::detail::ptr_node<std::pair<const boost::interprocess::ipcdetail::sync_id,void *>>>
1>  ,            Compare=boost::interprocess::ipcdetail::sync_handles::address_less
1>          ]
1>          C:\Users\Mike\Documents\boost_1_55_0\boost/container/map.hpp(83) : see reference to class template instantiation 'boost::container::container_detail::rbtree<Key,std::pair<const Key,T>,boost::container::container_detail::select1st<std::pair<const Key,T>>,Compare,Allocator>' being compiled
1>          with
1>          [
1>              Key=const boost::interprocess::ipcdetail::sync_id *
1>  ,            T=boost::unordered::iterator_detail::iterator<boost::unordered::detail::ptr_node<std::pair<const boost::interprocess::ipcdetail::sync_id,void *>>>
1>  ,            Compare=boost::interprocess::ipcdetail::sync_handles::address_less
1>  ,            Allocator=std::allocator<std::pair<const boost::interprocess::ipcdetail::sync_id *const ,boost::unordered::iterator_detail::iterator<boost::unordered::detail::ptr_node<std::pair<const boost::interprocess::ipcdetail::sync_id,void *>>>>>
1>          ]
1>          C:\Users\Mike\Documents\boost_1_55_0\boost/interprocess/sync/windows/sync_utils.hpp(226) : see reference to class template instantiation 'boost::container::map<const boost::interprocess::ipcdetail::sync_id *,boost::unordered::iterator_detail::iterator<boost::unordered::detail::ptr_node<T>>,boost::interprocess::ipcdetail::sync_handles::address_less,std::allocator<std::pair<const Key,boost::unordered::iterator_detail::iterator<boost::unordered::detail::ptr_node<T>>>>>' being compiled
1>          with
1>          [
1>              T=std::pair<const boost::interprocess::ipcdetail::sync_id,void *>
1>  ,            Key=const boost::interprocess::ipcdetail::sync_id *
1>          ]

我正在使用Visual Studio Express 2013 for Windows Desktop和boost 1.55.0。

我尝试了其他的boost库,没有任何问题...此外,我正在使用x64版本的发布构建。


你能在你的问题中包含编译器错误吗?它只是找不到头文件,还是头文件报告了错误? - Joe Z
好的,我希望这可以帮到你... - SkyRipper
3个回答

3

谢谢,这解决了第一个问题,但我仍然收到关于#include <boost/interprocess/mapped_region.hpp>的错误。 - SkyRipper

3
Boost 1.55尚未完全支持Visual Studio 2013编译器。
要么:
- 使用Visual Studio 2012工具链 - 或尝试从svn co http://svn.boost.org/svn/boost/trunk boost-trunk获取最新源代码 - 或自己修补boost(别忘了上传您的补丁) - 或等待其他人修补。您可以通过提交错误报告来加速此过程
编辑:
刚刚检查了boost-trunk,并已经对boost/intrusive/detail/has_member_function_callable_with.hpp进行了修补,使用vs2013vs2013-nov-2013-ctp工具链都可以正常编译。因此,请尝试使用它。如果您有多个boost版本,请像我一样更改包含路径(在Makefile或VC项目属性中)。;)

请注意,最新的开发代码可能不稳定。不要将其用于最终用户生产。


谢谢,你知道有没有人修补了Boost以支持Visual Studio 2013吗? - SkyRipper
好的,我已经添加了一个链接到错误报告表格。提交吧! ;) - Ivan Aksamentov - Drop
我刚刚使用最新的 boost-trunk 进行了检查。无法编译。 - Ivan Aksamentov - Drop
@SkyRipper 我又检查了一遍,实际上 boost-trunk 编译正常。我只是忘记将包含搜索路径从 boost-release 更改为 boost-trunk。请注意,我无法链接和运行它,因为我还没有编译 boost-trunk 库。所以,这取决于您来检查 ;) 我会在答案中添加这个信息。 - Ivan Aksamentov - Drop
你写道你已经使用 vs2013-nov-2013-ctp 工具集成功编译了 Boost。你是如何做到的?我已经尝试过向 Boost 构建系统提供 toolset=msvc-12.0-ctp 等参数,但都不起作用。 - Frederik Aalund
显示剩余2条评论

1

是的,你需要说“using namespace boost::interprocess;”

修改这个问题后,你应该就可以了。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接