【问题标题】:C++ Boost errors in Visual Studio 2010 - errorLNK1104 and "Incompatible build options"Visual Studio 2010 中的 C++ Boost 错误 - errorLNK1104 和“不兼容的构建选项”
【发布时间】:2013-03-20 09:28:09
【问题描述】:

只需尝试构建从 Boost 教程复制和粘贴的代码。 (见下文)

我只有头文件,目前还没有构建库。

问题是我收到两个错误:

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;
};

关于如何获取该 lib 文件的任何说明,因为它似乎并不在任何地方的 Boost 标头唯一目录中,计算机搜索也找不到任何东西.. 将不胜感激。

干杯

编辑 1:

能够生成必要的 .lib 文件,但在 Visual Studio 命令提示符中导航 boost 目录并运行 bootstrap.bat,这会生成 b2.exe,我运行它并生成了所需的 stage/lib 目录二进制文件。

但是,现在我收到另一个错误..“错误 LNK1561:必须定义入口点”

我猜错误的循环还在继续:)

编辑 2:被引用的入口点是 main()。忘记主线了!哦,好吧,添加了一个主要的,一切都很好!

【问题讨论】:

标签: c++ visual-studio visual-c++ boost


【解决方案1】:

对于第一个错误:右键单击 VStudio 中的项目 -> 属性 -> 链接器 -> 常规 -> 附加库目录 "boost\stage\lib" 似乎您尝试链接错误的文件夹。还要检查文件

libboost_system-vc100-mt-gd-1_53.lib

在 boost\stage\lib 文件夹中。

【讨论】:

  • 好吧,最初我没有,我必须运行 boost 文件附带的 bootstrap.bat 来生成该文件。现在我有了那个 .lib 文件,当我以这种方式链接时,错误已经消失 - 干杯。但是,现在我有一个不同的错误......“错误 LNK1561:必须定义入口点”......有什么想法吗?
  • 运行 bootstrap.bat 后运行以下命令:( b2 --toolset=msvc-10.0 --build-type=complete stage ) 如果您使用 Visual Studio 2010。否则使用 msvc-11.0 进行可视化studio 2012。您也可以添加到命令 -j4 以加快此过程。 (如果您有四核,则为 4,如果您有双核,则为 2...)
  • 所以我运行了那个命令,它说更新了 2268 个目标并且命令提示符恢复了它的标准状态。然而,同样的错误仍然发生
  • 确保它不是最简单的错误:你有主函数吗?
  • 啊,拿着手机,它现在确实在工作。我错过了一个主要功能.. Doh!不过,我感谢您的帮助,但仍然需要引导后的该命令。谢谢
【解决方案2】:

如果您在构建中进行静态链接,则需要安装 boost 并提供库。安装后,您将能够在 VS 项目配置中找到并指定库的路径。

【讨论】:

    【解决方案3】:

    在我的情况下,发布模式运行良好,但调试模式显示此错误...

    试试这个: 在 VStudio Properties -> C/C++ -> Code General -> Runtime Library 中右键单击项目:将 /MT 更改为 /MTD。

    【讨论】:

      猜你喜欢
      • 2016-02-21
      • 1970-01-01
      • 2011-02-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多