升压短耳串口问题 [英] Boost Asio serial port issue

查看:170
本文介绍了升压短耳串口问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用在Windows系统$ C $个cblocks和下载加速,遵守和设置我的IDE变量和构建选项。我已经成功地使用其它Boost库,现在我需要在一个程序,读取和写入到串行端口工作。

I'm using CodeBlocks on a windows systems and have downloaded Boost, complied and setup my IDE variables and build options. I have been successfully using other boost libraries and now I need to work on a program that reads and writes to a serial port.

我无法得到我尝试编译ASIO串行端口的例子。下面,例如将产生如下code编译错误:

I can not get any example that I try to compile for asio serial port. The following, for example will generate a compile error which follows the code:

#include <iostream>
#include <boost/asio.hpp>
#include <boost/asio/serial_port.hpp>
#include <boost/thread.hpp>



int main()
{


    boost::asio::io_service io_service;
    boost::asio::serial_port port(io_service);


    return 0;

}

这是生成日志为上述code:

This is the build log for the above code:

Compiling: main.cpp
In file included from C:\Dev\boost_1_47_0/boost/thread/win32/thread_data.hpp:12,
                 from C:\Dev\boost_1_47_0/boost/thread/thread.hpp:15,
                 from C:\Dev\boost_1_47_0/boost/thread.hpp:13,
                 from C:\Users\bjune\Documents\CodeBlocks\hellow\main.cpp:4:
C:\Dev\boost_1_47_0/boost/thread/win32/thread_heap_alloc.hpp:59: warning: inline function 'void* boost::detail::allocate_raw_heap_memory(unsigned int)' declared as  dllimport: attribute ignored
C:\Dev\boost_1_47_0/boost/thread/win32/thread_heap_alloc.hpp:69: warning: inline function 'void boost::detail::free_raw_heap_memory(void*)' declared as  dllimport: attribute ignored
C:\Users\bjune\Documents\CodeBlocks\hellow\main.cpp: In function 'int main()':
C:\Users\bjune\Documents\CodeBlocks\hellow\main.cpp:13: error: 'serial_port' is not a member of 'boost::asio'
C:\Users\bjune\Documents\CodeBlocks\hellow\main.cpp:13: error: expected ';' before 'port'
C:\Dev\boost_1_47_0/boost/system/error_code.hpp: At global scope:

任何意见?

推荐答案

升压/ ASIO / serial_port_base.hpp 文件(有点简单):

#if defined(BOOST_ASIO_HAS_IOCP) || !defined(BOOST_WINDOWS)
#  define BOOST_ASIO_HAS_SERIAL_PORT 1
#endif

所以BOOST_ASIO_HAS_SERIAL_PORT是Windows真的只有BOOST_ASIO_HAS_IOCP也是如此。

So BOOST_ASIO_HAS_SERIAL_PORT is true in Windows only if BOOST_ASIO_HAS_IOCP is also true.

然后,从升压/ ASIO /细节/ win_iocp_io_service_fwd.hpp

#if defined(BOOST_WINDOWS)
#if defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0400)

// Define this to indicate that IOCP is supported on the target platform.
#  define BOOST_ASIO_HAS_IOCP 1
#endif
#endif

所以,如果我下面是正确的,你需要定义_WIN32_WINNT到的0x0400或以上来启用它。

So, if I'm following it right, you need to define _WIN32_WINNT to 0x0400 or above to enable it.

这篇关于升压短耳串口问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆