【发布时间】:2012-09-16 16:17:12
【问题描述】:
我只想问这个非常琐碎的问题,我不知道这是否是正确的问题,或者以前是否有人问过这个问题,我知道这可以通过访问关于 boost 的文档来解决。但是我真的很迷茫,并且卡在C::B 中配置boost.thread。
在这方面我只是一个初学者,目前正在学习如何制作 Windows 应用程序,并不认真,只是为了学习目的。我只是注意到我真的需要多线程的概念才能让它工作。所以我决定使用 Boost 库,我完全按照 boost wiki 在构建库时所说的那样做,我认为我没有做错什么。
我从文档中运行了一些代码,这些代码仅是标题,它可以完美运行,但是 boosts 中包含的库需要某种特殊处理,包括 boost.thread,我遇到了困难。我知道#includ-ing 在我的文件中不会使Boost.thread 起作用。我从online tutorial(我在那里找到的多线程页面上的第一个代码)中找到的这个基本代码出错了,它会产生一个错误,指出没有这样的文件目录。
||=== Multithreading_sample, Debug ===|
C:\Documents and Settings\Owner\Desktop\Programming\C++\Dev
C++\App\Multithreading_sample\Multithreading_sample\main.cpp|1|boost/thread.hpp: No such
file or directory|
C:\Documents and Settings\Owner\Desktop\Programming\C++\Dev
C++\App\Multithreading_sample\Multithreading_sample\main.cpp||In function `void
wait(int)':|
C:\Documents and Settings\Owner\Desktop\Programming\C++\Dev
C++\App\Multithreading_sample\Multithreading_sample\main.cpp|6|error: `boost' has not
been declared|
C:\Documents and Settings\Owner\Desktop\Programming\C++\Dev
C++\App\Multithreading_sample\Multithreading_sample\main.cpp|6|error: `boost' has not
been declared|
C:\Documents and Settings\Owner\Desktop\Programming\C++\Dev
C++\App\Multithreading_sample\Multithreading_sample\main.cpp|6|error: `seconds' cannot
be used as a function|
C:\Documents and Settings\Owner\Desktop\Programming\C++\Dev
C++\App\Multithreading_sample\Multithreading_sample\main.cpp|6|error: `sleep' undeclared
(first use this function)|
C:\Documents and Settings\Owner\Desktop\Programming\C++\Dev
C++\App\Multithreading_sample\Multithreading_sample\main.cpp|6|error: (Each undeclared
identifier is reported only once for each function it appears in.)|
C:\Documents and Settings\Owner\Desktop\Programming\C++\Dev
C++\App\Multithreading_sample\Multithreading_sample\main.cpp||In function `int main()':|
C:\Documents and Settings\Owner\Desktop\Programming\C++\Dev
C++\App\Multithreading_sample\Multithreading_sample\main.cpp|20|error: `boost' has not
been declared|
C:\Documents and Settings\Owner\Desktop\Programming\C++\Dev
C++\App\Multithreading_sample\Multithreading_sample\main.cpp|20|error: expected `;'
before "t"|
C:\Documents and Settings\Owner\Desktop\Programming\C++\Dev
C++\App\Multithreading_sample\Multithreading_sample\main.cpp|20|warning: statement is a
reference, not call, to function `thread'|
C:\Documents and Settings\Owner\Desktop\Programming\C++\Dev
C++\App\Multithreading_sample\Multithreading_sample\main.cpp|20|warning: statement has
no effect|
C:\Documents and Settings\Owner\Desktop\Programming\C++\Dev
C++\App\Multithreading_sample\Multithreading_sample\main.cpp|21|error: `t' undeclared
(first use this function)|
||=== Build finished: 9 errors, 2 warnings ===|
我知道它没有检测到我的boost.thread 库,我不知道在这部分中去哪里。我已经搜索了谷歌,但我认为我最好的选择是单独构建 1boost.thread1,如 here 所示,我不知道下一步该做什么。
- 我的 boost 库版本是 1.51.0,我的 C::B 是 10.05,在 windows XP 上运行,我想在我的 CodeBlocks 中使用
boost.thread。我只想粘贴代码并运行它,看看它是如何工作的。 - 我的 MinGW 版本是 3.4.2
【问题讨论】:
-
multithreading section 中的第二个代码示例适用于 C::B、GCC 4.7.1 和 Boost 1.49.0。
-
你有没有在你的 CodeBlocks 中配置 boost.thread 之类的东西,你是如何让它工作的?第一个代码对我不起作用。我还没有尝试过第二个代码。我想我会寻找预编译版本的 boost 线程,看看我是否可以从那里解决问题。感谢您的回复。
-
我从 nuwen.net/mingw.html 获得了 MinGW,其中包括 Boost。它编译良好,无需对标头内部进行任何配置更改,但链接需要
-lboost_thread。 -
好吧,也许我会把我的 MinGW 更新到最新版本,看看问题是否会自行解决。
-
最新版本的 boost 是不是有点不稳定?如果是这种情况,我看到其他使用 boost 的人对旧版本没有问题。
标签: c++ boost mingw codeblocks boost-thread