Boost::Asio for C++ 的问题

发布于 2024-08-28 00:59:09 字数 1017 浏览 4 评论 0原文

在我的学士论文中,我正在实现一个分布式版本的算法,用于分解大整数(找到质因式分解)。这在例如RSA密码系统的安全性方面具有应用。

我的愿景是,客户端(Linux 或 Windows)将下载应用程序并计算一些数字(这些数字是独立的,因此适合并行化)。这些号码(不经常找到)将被发送到主服务器,以收集这些号码。一旦主服务器收集到足够的数量,它将完成其余的计算,这不能轻易地并行化。

无论如何,关于技术细节。我正在考虑使用 Boost::Asio 来做套接字客户端/服务器实现,用于客户端与主服务器的通信。由于我想同时针对 Linux 和 Windows 进行编译,因此我认为 Windows 是一个很好的起点。所以我下载了 Boost 库并编译了它,正如它在 Boost 入门页面

引导程序

.\bjam

一切都编译得很好。然后我尝试编译来自 Asio 的教程示例之一 client.cpp(此处..编辑:由于限制而无法发布链接)。我使用 Microsoft Visual Studio 2008 中的 Visual C++ 编译器,如下所示:

cl /EHsc /ID:\Downloads\boost_1_42_0 client.cpp

但我收到此错误:

/out:client.exe

客户端.obj

链接:致命错误 LNK1104:无法打开文件“libboost_system-vc90-mt-s-1_42.lib”

任何人都知道可能出了什么问题,或者我如何继续前进?我几乎整个星期都在尝试让 C++ 工作的简单客户端/服务器套接字程序,但没有运气。严重的挫败感袭来。

提前谢谢你。

For my bachelors thesis, I am implementing a distributed version of an algorithm for factoring large integers (finding the prime factorisation). This has applications in e.g. security of the RSA cryptosystem.

My vision is, that clients (linux or windows) will download an application and compute some numbers (these are independant, thus suited for parallelization). The numbers (not found very often), will be sent to a master server, to collect these numbers. Once enough numbers have been collected by the master server, it will do the rest of the computation, which cannot be easily parallelized.

Anyhow, to the technicalities. I was thinking to use Boost::Asio to do a socket client/server implementation, for the clients communication with the master server. Since I want to compile for both linux and windows, I thought windows would be as good a place to start as any. So I downloaded the Boost library and compiled it, as it said on the Boost Getting Started page:

bootstrap

.\bjam

It all compiled just fine. Then I try to compile one of the tutorial examples, client.cpp, from Asio, found (here.. edit: cant post link because of restrictions). I am using the Visual C++ compiler from Microsoft Visual Studio 2008, like this:

cl /EHsc /I D:\Downloads\boost_1_42_0 client.cpp

But I get this error:

/out:client.exe

client.obj

LINK : fatal error LNK1104: cannot open file 'libboost_system-vc90-mt-s-1_42.lib'

Anyone have any idea what could be wrong, or how I could move forward? I have been trying pretty much all week, to get a simple client/server socket program for c++ working, but with no luck. Serious frustration kicking in.

Thank you in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤城病女 2024-09-04 00:59:09

构建失败的原因是找不到包含boost系统的库文件。 Boost 包含一个“方便的”自动链接功能,这样当您包含二进制库的头文件(而不是仅包含头文件的库)时,Boost 会自动告诉编译器它应该链接到库中。这样做的缺点是 boost 不会告诉编译器在哪里可以找到该库。

简短的答案是进一步阅读 boost 入门指南。本页向您展示如何向编译器命令行添加必要的标志:Windows 入门:从命令行链接

您要做的第一件事是找到 .lib 文件。 Boost 将它们隐藏在深层目录结构中,因此请从运行 bjam 的目录开始搜索它。记下文件所在的目录。您可能还希望使用 bootstrap --prefix=/some/install/locationbjam install 将 boost 安装在构建它的源目录之外的其他位置。

您是使用 Visual Studio 解决方案还是在命令行上构建项目?

如果您使用的是解决方案文件,请在解决方案属性中找到链接页面。应该有一个框,您可以在其中输入其他库路径。将 boost .lib 文件所在的目录添加到此框中。

如果您在命令链接上使用 cl,请熟悉 cl链接。您可以使用cl选项/link将命令传递给链接器,您要查找的链接器命令是/libpath

The reason the build is failing is because it cannot find the library file containing boost system. Boost includes a "handy" autolinking feature, such that when you include a header file for a binary libaray (as opposed to a header only library), boost automatically tells the compiler that it should link in the library. The downside to this is that boost doesn't tell the compiler where to find the library.

The short answer is to read a little further in the boost getting started guide. This page shows you how to add the necessary flags to the compiler command line: Getting started on windows: linking from the command line.

The first thing you have to do is find the .lib file. Boost hides them in a deep directory structure, so search for it starting in the directory you ran bjam from. Make note of the directory where the file is. You may also wish to use bootstrap --prefix=/some/install/location and bjam install to install boost somewhere other than the source directory in which you built it.

Are you building your project using a Visual Studio solution, or on the command line?

If you are using a solution file, find the link page in the solution properties. There should be a box where you can enter additional library paths. Add the directory in which you boost .lib files reside to this box.

If you are using cl on the command link, familiarize yourself with the command line options for cl and link. You can pass commands to the linker using the cl option /link, and the linker command you are looking for is /libpath.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文