繁体   English   中英

如何在Windows上的CodeBlocks中构建和配置boost.thread

[英]How to build and configure boost.thread in CodeBlocks on Windows

我只是想问这个非常琐碎的问题,我不知道这是对的问题还是以前曾问过的问题,我知道可以通过访问boost的文档来解决。 但是我真的迷失了,并且停留在C::B配置boost.thread

我只是一个初学者,目前正在学习如何制作Windows应用程序,不是很认真,仅出于学习目的。 我只是注意到,我真的需要多线程的概念才能使其工作。 因此,我决定使用Boost库,我做了boost wiki在构建库时所说的,我认为我没有做错什么。

我从文档中运行了一些仅头文件的代码,它可以完美地工作,但是boosts中包含一些库,需要对boost.thread进行某种形式的特殊处理,而我遇到了麻烦。 我知道#在文件中包含它不会使Boost.thread起作用。 我从在线教程中找到的基本代码中发现了错误(我在那儿找到的多线程页面上的第一个代码)产生了一个错误,提示没有此类文件目录。

||=== 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如图所示在这里 ,我不知道下一步该怎么做。

  • 我Boost库的版本是1.51.0我的C :: B是10.05 Windows XP上运行,我想用boost.thread在我的代码块。 我要做的只是粘贴代码并运行它,然后看它如何工作。
  • 我的MinGW版本是3.4.2

最终,经过数天的研究,在网上进行谷歌搜索和交叉引用众多解决方案,我终于在所提供的网站上制作了第一个代码。

首先,我所做的是,我将extract_directory包含为全局变量中内置字段的基础。 然后转到项目选项,然后单击层次结构中的项目名称并搜索目录,然后在“编译器”选项卡上添加了$(#boost.include),在链接器选项卡上添加了$(boost)\\ stage \\ lib。

我从头开始重新构建boost(esp构建boost.thread库),然后再次遵循文档中的确切说明,然后最终出现一些错误,提示Boost :: system上存在未定义的引用错误。 解决此问题的方法是将我的项目链接到该boost.system(在我的情况下,这是我的stage \\ lib文件夹中的文件)。

我将此库链接到我的项目libboost_system-mgw34-mt-1_51.a

当我编译程序时,发生错误,提示对boost :: chrono的未定义引用,该库的名称为:

libboost_chrono-mgw34-mt-1_51.a

并且我也将我的项目链接到它,就像我为boost :: system做的一样。

并编译! 在没有任何警告的情况下,我从这次经验中学到的是,我必须寻找所需的库,到目前为止,我所做的只是将boost.thread库与错误链接,只是不断对boost.system说未定义的参考错误。我不知道这与Boost线程或其他库有关(这是我弄乱东西之前遇到的第一个错误)。 我认为每个Boost库中都有另一个库中的多个函数调用,因此我也必须与它们链接,这也需要此类调用。

谢谢你们的友好回应。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM