简体   繁体   English

如何配置Qt Creator在Windows中使用Boost

[英]How to configure Qt Creator to use Boost in Windows

I created a Qt project in Ubuntu and everything went smoothly. 我在Ubuntu中创建了一个Qt项目,一切顺利。 However, I also need deploy it on Windows. 但是,我还需要在Windows上部署它。 It uses Boost libraries(the big problem). 它使用Boost库(最大的问题)。

I've been searching for hours to find a solution, but didn't have luck. 我一直在寻找解决方案的几个小时,但没有运气。 I tried to install Boost libraries and link it with mingw; 我试图安装Boost库并将其与mingw链接; I think I missed something. 我想我错过了什么。 Here is what I did and downloading the lastest version: 这是我做的和下载最新版本:

1) ran .\\bootstrap 1)跑。\\ bootstrap
2) then .\\b2 --prefix=C:\\boost install 2)然后。\\ b2 --prefix = C:\\ boost install

Sadly didn't install correctly. 可悲的是没有正确安装。 I got only 2 folder(bin and share) but no headers. 我只有2个文件夹(bin和共享)但没有标题。

However, here ( http://nuwen.net/ ) I found a bundle(Mingw+Boost and other libraries). 但是,在这里( http://nuwen.net/ )我找到了一个包(Mingw + Boost和其他库)。 This has everything I need. 这有我需要的一切。

Now I think the issue is .pro file, because I have a lot of undefined references. 现在我认为问题是.pro文件,因为我有很多未定义的引用。 Here is .pro file with everything I tried (some commented): http://pastebin.com/pBFMTAd8 这是.pro文件,包含我尝试的所有内容(一些评论): http//pastebin.com/pBFMTAd8

Your help is appreciated! 非常感谢您的帮助!

I did solve the problem myself. 我自己确实解决了这个问题。 And here is how I did it. 以下是我的表现方式。 First of all, it is required to have boost library compiled with same compiler you're using with Qt. 首先,需要使用与Qt一起使用的相同编译器编译的boost库。
If you're using msvc, then you're lucky because Boost guys did you a favour and compiled libraries for you. 如果你正在使用msvc,那么你很幸运,因为Boost的人帮你一个忙,并为你编译了库。 You can download them here: http://sourceforge.net/projects/boost/files/boost-binaries/ . 您可以在此处下载: http//sourceforge.net/projects/boost/files/boost-binaries/
If you're using mingw (which does come in bundle with Qt), you can do this: 如果您正在使用mingw(它与Qt捆绑在一起),您可以这样做:

  • add mingw compiler to Windows PATH variable: 将mingw编译器添加到Windows PATH变量:
    ~ go to control panel and search for System; 〜转到控制面板并搜索System;
    ~ add mingw's path(eg C:\\Qt\\Tools\\mingw\\bin) to PATH variable by appending ';' 〜通过附加';'将mingw的路径(例如C:\\ Qt \\ Tools \\ mingw \\ bin)添加到PATH变量 to your path(eg: ";C:\\Qt\\Tools\\mingw\\bin") 到你的路径(例如:“; C:\\ Qt \\ Tools \\ mingw \\ bin”)
  • compile Boost libraries: 编译Boost库:
    ~ unzip boost archive 〜解压缩存档
    ~ open a Command Line window, go in the unzipped boost folder, then go in folder tools/build/v2/engine 〜打开一个命令行窗口,进入解压缩的boost文件夹,然后进入文件夹tools / build / v2 / engine
    ~ you have you build installer with mingw toolset: .\\build --toolset=mingw 〜你用mingw工具集构建安装程序:。\\ build --toolset = mingw
    ~ this will create 2 files in folder bin.ntx86 or something similar; 〜这将在文件夹bin.ntx86或类似的东西中创建2个文件; copy the files bjam and b2 in the unzipped boost folder; 将文件bjam和b2复制到解压缩的boost文件夹中;
    ~ now go in boost folder and start build it: .\\b2 --toolset=mingw --build-type=complete stage (there is good tutorial to install it along with eclipse : http://theseekersquill.wordpress.com/2010/08/24/howto-boost-mingw/ ) 〜现在进入boost文件夹并开始构建它:。\\ b2 --toolset = mingw --build-type =完成阶段(有很好的教程可以和eclipse一起安装它: http//theseekersquill.wordpress.com/2010 / 08/24 / howto-boost-mingw /
    note: this gonna take few hours, so may want to watch a movie or what ever you want to do meanwhile. 注意:这需要几个小时,所以可能想看电影或者你想做什么同时。 However you have the option to speed up things a little bit by adding another argument to the build command: -j N, where N is how many cores your processor have. 但是,您可以选择通过在构建命令中添加另一个参数来加快速度:-j N,其中N是处理器具有的核心数。
  • when build has finished, you can now link the library in Qt. 当构建完成后,您现在可以在Qt中链接库。 To do this you need to modify .pro file. 为此,您需要修改.pro文件。 First you'll have to tell Qt where are headers are located, and you do so by adding: 首先,你必须告诉Qt标题的位置,你可以通过添加:
    INCLUDEPATH += path_to_boost_folder, eg : INCLUDEPATH += C:/boost_1_54_0 INCLUDEPATH + = path_to_boost_folder,例如:INCLUDEPATH + = C:/ boost_1_54_0
    ~ also if you're using libraries which requires link, for example system and filesystem you have to link them separately: 〜如果您使用需要链接的库,例如系统和文件系统,您必须单独链接它们:
    LIBS += "C:/boost_1_54_0/stage/lib/libboost_filesystem-mgw48-1_54.a", LIBS + =“C:/boost_1_54_0/stage/lib/libboost_filesystem-mgw48-1_54.a”,
    LIBS += "C:/boost_1_54_0/stage/lib/libboost_system-mgw48-1_54.a" LIBS + =“C:/boost_1_54_0/stage/lib/libboost_system-mgw48-1_54.a”
  • after modifying the .pro file, run qmake, then rebuild. 修改.pro文件后,运行qmake,然后重建。

Hope this works for you too! 希望这也适合你!

Update : The folder hierarchy has change. 更新 :文件夹层次结构已更改。 For building the library, one should read the documentation associated with each version and Boost.Build's documentation . 要构建库,应该阅读与每个版本相关的文档Boost.Build的文档 Building the library from the root folder is easier ( Building Boost 1.52 with MinGW ): 从根文件夹构建库更容易( 使用MinGW构建Boost 1.52 ):

C:\boost_1_60_0> bootstrap.bat mingw  
C:\boost_1_60_0> .\b2 --toolset=gcc -j N --build-type=complete

building boost will not put the headers, the headers are for the developer when he creates new code. 构建boost不会放置标题,标题是为开发人员创建新代码时。 The installed dirs are the binaries for distribution. 已安装的目录是用于分发的二进制文件。

see http://www.boost.org/doc/libs/1_54_0/more/getting_started/windows.html#prepare-to-use-a-boost-library-binary http://www.boost.org/doc/libs/1_54_0/more/getting_started/windows.html#prepare-to-use-a-boost-library-binary

this will install libraries, that you use at runtime (not compile time). 这将安装您在运行时使用的库(不是编译时)。 Because you add this bin folder to your path and that is why when runing an app build with boost it will run and not say "could not find xxx.dll" 因为你将这个bin文件夹添加到你的路径,这就是为什么当使用boost运行应用程序构建时它会运行而不是说“找不到xxx.dll”

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

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