2011-08-16 2 views
0

J'utilise CodeBlocks sur un système Windows et j'ai téléchargé Boost, j'ai respecté et configuré mes variables IDE et les options de compilation. J'ai utilisé avec succès d'autres bibliothèques boost et maintenant je dois travailler sur un programme qui lit et écrit sur un port série.Boost numéro de port série Asio

Je ne peux obtenir aucun exemple que j'essaie de compiler pour le port série asio. Voici, par exemple, génère une erreur de compilation qui suit le 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; 

} 

Ceci est le journal de construction pour le code ci-dessus:

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: 

Tous les conseils ??

Répondre

3

De l'boost/ASIO/fichier serial_port_base.hpp (un peu simplifié):

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

Alors BOOST_ASIO_HAS_SERIAL_PORT est vrai que dans Windows si BOOST_ASIO_HAS_IOCP est également vrai.

Puis, à partir boost/ASIO/détails/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 

Donc, si je suis à droite, vous devez définir _WIN32_WINNT à 0x0400 ou au-dessus pour l'activer.