只需尝试构建从 Boost 教程复制和粘贴的代码。 (见下文)
我只有头文件,到目前为止还没有构建库。
问题是我遇到了两个错误:
错误 1 错误 LNK1104:无法打开文件“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 测试
2 IntelliSense:#error 指令:“不兼容的构建选项”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;
};
有关如何获取该 lib 文件的任何说明,因为它似乎确实不在任何地方的 Boost 仅 header 目录中,计算机搜索也找不到任何内容.. 将不胜感激。
干杯
编辑 1:
能够生成必要的 .lib 文件,但在 Visual Studio 命令提示符下导航 boost 目录并运行 bootstrap.bat,这会生成 b2.exe,我运行了它并生成了所需的 stage/lib 目录二进制文件。
但是,现在我遇到了另一个错误……“错误 LNK1561:必须定义入口点”
我想错误循环还在继续:)
编辑 2:所引用的入口点是 main()。主线忘记了!哦,好吧,添加到 main 中,一切都很好!
最佳答案
对于第一个错误:右键单击 VStudio 中的项目 -> 属性 -> 链接器 -> 常规 -> 附加库目录“boost\stage\lib” 看来您试图链接错误的文件夹。还要检查文件
libboost_system-vc100-mt-gd-1_53.lib
在 boost\stage\lib 文件夹中。
关于Visual Studio 2010 中的 C++ Boost 错误 - errorLNK1104 和 "Incompatible build options",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15519664/