2011-08-16 112 views
0

我在Windows系統上使用CodeBlocks,並下載了Boost,編譯並設置了我的IDE變量和編譯選項。我一直在成功地使用其他boost庫,現在我需要處理讀取和寫入串行端口的程序。Boost Asio串行端口問題

我無法獲得任何示例,我嘗試編譯爲asio串行端口。下面,例如將產生下面的代碼編譯錯誤:

#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; 

} 

這是生成日誌上面的代碼:

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: 

任何意見??

回答

3

升壓/ 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也是如此。

然後,從升壓/ 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或以上來啓用它。