Boostチュートリアルからコピーして貼り付けたコードを作成してみてください。(下記参照)
私はヘッダーのみのファイルを持っていますが、まだビルドされたライブラリはありません。
問題は、2つのエラーが発生することです。
Error 1 error LNK1104: cannot open file 'libboost_system-vc100-mt-gd-1_53.lib' \\selafap01\homedrives\mgibson\My Documents\Visual Studio 2010\Projects\C++ Boost Test\C++ Boost Test\LINK C++ Boost Test
2 IntelliSense: #error directive: "Incompatible build options" c:\boost\config\auto_link.hpp 111 4
私が何をしていても、.libファイルが必要なようですが、実際にはその方法がわかりません。
#include <boost/asio.hpp>
class SimpleSerial
{
public:
/**
* Constructor.
* \param port device name, example "/dev/ttyUSB0" or "COM4"
* \param baud_rate communication speed, example 9600 or 115200
* \throws boost::system::system_error if cannot open the
* serial device
*/
SimpleSerial(std::string port, unsigned int baud_rate)
: io(), serial(io,port)
{
serial.set_option(boost::asio::serial_port_base::baud_rate(baud_rate));
}
/**
* Write a string to the serial device.
* \param s string to write
* \throws boost::system::system_error on failure
*/
void writeString(std::string s)
{
boost::asio::write(serial,boost::asio::buffer(s.c_str(),s.size()));
}
/**
* Blocks until a line is received from the serial device.
* Eventual '\n' or '\r\n' characters at the end of the string are removed.
* \return a string containing the received line
* \throws boost::system::system_error on failure
*/
std::string readLine()
{
//Reading data char by char, code is optimized for simplicity, not speed
using namespace boost;
char c;
std::string result;
for(;;)
{
asio::read(serial,asio::buffer(&c,1));
switch(c)
{
case '\r':
break;
case '\n':
return result;
default:
result+=c;
}
}
}
private:
boost::asio::io_service io;
boost::asio::serial_port serial;
};
Boostヘッダーのみのディレクトリには実際にはないように見えるため、そのlibファイルを取得する方法についての指示はありません。コンピュータ検索でも何も見つかりません。
乾杯
編集1:
必要な.libファイルを生成できましたが、Visual Studioコマンドプロンプトでboostディレクトリをナビゲートし、bootstrap.batを実行しました。これにより、b2.exeが生成され、それを実行すると、必要なバイナリを使用してstage/libディレクトリが生成されました。
ただし、別のエラーが発生します。「エラーLNK1561:エントリポイントを定義する必要があります」
エラーの輪は続くと思います:)
編集2:参照されているエントリポイントはmain()でした。メインを忘れた!まあ、メインに追加して、すべてが順調です!