0

BoostAsioを使用して、C ++でarduinoスローシリアルと通信しようとしています。Visual Studio でコンパイルされるこのコードを見つけましたが、linux-ubuntu ではコンパイルに失敗します。

コンパイル時にフラグを使用しません。これが問題でしょうか?

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

#define PORT_LINUX "/dev/ttyUSB0"
#define PORT_WINDOW "COM7"


#define SECURITY_CAMERA 1
#define FIRE_SENSOR 2
#define VOICE_SENSOR 3
#define DISTANCE_SENSOR 4


// Base serial settings
serial_port_base::baud_rate BAUD(9600);
serial_port_base::flow_control FLOW( serial_port_base::flow_control::none );
serial_port_base::parity PARITY( serial_port_base::parity::none );
serial_port_base::stop_bits STOP( serial_port_base::stop_bits::one );
serial_port_base::character_size CSIZE(serial_port_base::character_size::character_size(8U));


//serial_port_base::stop_bits STOP( serial_port_base::stop_bits::one );

int main(){
  io_service io;
  serial_port port( io, PORT_LINUX );

  // Setup port - base settings
  port.set_option( BAUD );
  port.set_option( FLOW );
  port.set_option( PARITY );
  port.set_option( STOP );
  port.set_option( CSIZE );

  char opcode,priority;
  int num;

  while(1){
    num = read(port,buffer(&opcode,1));
    num = read(port,buffer(&priority,1));
    cout << opcode<<" "<<priority<<endl;
  }

  return 0;
}

コンパイラ エラー:

error: expected unqualified-id before numeric constant
In file included from /usr/include/boost/asio/serial_port_service.hpp:25:0,
                 from /usr/include/boost/asio/basic_serial_port.hpp:30,
                 from /usr/include/boost/asio.hpp:25,
                 from main.cpp:2:
/usr/include/boost/asio/detail/reactive_serial_port_service.hpp: In instantiation
  of ‘static boost::system::error_code 
  boost::asio::detail::reactive_serial_port_service::store_option(const void*,
  termios&, boost::system::error_code&) [with SettableSerialPortOption = int]’:
/usr/include/boost/asio/detail/reactive_serial_port_service.hpp:126:20:
  required from ‘boost::system::error_code  
  boost::asio::detail::reactive_serial_port_service::set_option(
  boost::asio::detail::reactive_serial_port_service::implementation_type&,
  const SettableSerialPortOption&, boost::system::error_code&) [with 
  SettableSerialPortOption = int; 
  boost::asio::detail::reactive_serial_port_service::implementation_type = 
  boost::asio::detail::reactive_descriptor_service::implementation_type]’
/usr/include/boost/asio/serial_port_service.hpp:167:53:   required from 
  ‘boost::system::error_code 
  boost::asio::serial_port_service::set_option(
  boost::asio::serial_port_service::implementation_type&, const 
  SettableSerialPortOption&, boost::system::error_code&) [with 
  SettableSerialPortOption = int;
  boost::asio::serial_port_service::implementation_type = 
  boost::asio::detail::reactive_descriptor_service::implementation_type]’
/usr/include/boost/asio/basic_serial_port.hpp:390:5:   required from ‘void 
  boost::asio::basic_serial_port<SerialPortService>::set_option(const 
  SettableSerialPortOption&) [with SettableSerialPortOption = int;
  SerialPortService = boost::asio::serial_port_service]’
main.cpp:35:26:   required from here
/usr/include/boost/asio/detail/reactive_serial_port_service.hpp:194:20:  error:
  request for member ‘store’ in ‘*(const int*)option’, which is of non-class type
  ‘const int’
4

1 に答える 1

1

他の場所で定義されているマクロとの衝突により、コンパイルが失敗していCSIZEます。serial_port_base::character_size CSIZE両方の場所など、変数に別の識別子を指定すると、CHAR_SIZEコンパイルされます。

コンパイラ エラー「expected unqualified-id before numeric constant」CSIZEは、数値定数として処理されていたことを示唆していました。そのヒントをg++ -E -dD -dI -Pもとに、フラグを指定してコンパイラを呼び出し、ソースの前処理を実行し、マクロとインクルード ディレクティブを保持しました。出力は、私のシステムでbits/termios.h#define CSIZE 0000060.

于 2013-07-17T13:30:19.363 に答える