
Running Eclipse 3.7.2 on Ubuntu 12.10 (i386) with Boost 1.49 Trying to get a serial port running with a callback Found: http://www.webalice.it/fede.tft/serial_port/serial_port.html and the source: git clone: git://gitorious.org/serial-port/serial-port.git When I compile a serial port example 4 with g++ I do not get any problems. When I compile exactly the same class from Eclipse I get an error. thread t(boost::bind(&asio::io_service::run, &pimpl->io)); // Offending code ------------------------------------------------------------------ 'boost::bind' is ambiguous ' Candidates are: boost::_bi::bind_t<unsigned int,unsigned int (*)(boost::system::error_code &),boost::_bi::list1<boost::_bi::value<boost::asio::io_service *>>> bind(unsigned int (*)(boost::system::error_code &), boost::asio::io_service *) boost::_bi::bind_t<unsigned int,boost::_mfi::mf0<unsigned int,boost::asio::io_service>,boost::_bi::list1<boost::_bi::value<boost::asio::io_service *>>> bind(unsigned int (boost::asio::io_service::*)(), boost::asio::io_service *) ' AsyncSerial.cpp /nodeserver/src line 102 Semantic Error ------------------------------------------------------------------ pimpl->io is a boost::asio::io_service class AsyncSerialImpl: private boost::noncopyable { public: ... boost::asio::io_service io; ///< Io service object ... }; Someone suggest I declare a pointer to the run function, to resolve the problem, which I tried, but didnt get it right. How do I declare a variable, which can be assigned the io_service::run function? <?> myrun = &boost::asio::io_service::run; Any other ideas? Why compile and link in the makefile and not inside Eclipse? Tried on a Ubuntu 13.04 machine with the same problem. BR Ulf Samuelsson ==================================================================== Part of the code. ------------------------ void AsyncSerial::open(const std::string& devname, unsigned int baud_rate, asio::serial_port_base::parity opt_parity, asio::serial_port_base::character_size opt_csize, asio::serial_port_base::flow_control opt_flow, asio::serial_port_base::stop_bits opt_stop) { if(isOpen()) close(); setErrorStatus(true);//If an exception is thrown, error_ remains true pimpl->port.open(devname); pimpl->port.set_option(asio::serial_port_base::baud_rate(baud_rate)); pimpl->port.set_option(opt_parity); pimpl->port.set_option(opt_csize); pimpl->port.set_option(opt_flow); pimpl->port.set_option(opt_stop); //This gives some work to the io_service before it is started pimpl->io.post(boost::bind(&AsyncSerial::doRead, this)); --------------------------------------------------------------------------------------------------------------------------- thread t(boost::bind(&asio::io_service::run, &pimpl->io)); // Offending code --------------------------------------------------------------------------------------------------------------------------- pimpl->backgroundThread.swap(t); setErrorStatus(false);//If we get here, no error pimpl->open=true; //Port is now open } class AsyncSerialImpl: private boost::noncopyable { public: AsyncSerialImpl(): io(), port(io), backgroundThread(), open(false), error(false) {} boost::asio::io_service io; ///< Io service object boost::asio::serial_port port; ///< Serial port object boost::thread backgroundThread; ///< Thread that runs read/write operations bool open; ///< True if port open bool error; ///< Error flag mutable boost::mutex errorMutex; ///< Mutex for access to error /// Data are queued here before they go in writeBuffer std::vector<char> writeQueue; boost::shared_array<char> writeBuffer; ///< Data being written size_t writeBufferSize; ///< Size of writeBuffer boost::mutex writeQueueMutex; ///< Mutex for access to writeQueue char readBuffer[AsyncSerial::readBufferSize]; ///< data being read /// Read complete callback boost::function<void (const char*, size_t)> callback; };