How to configure Qt Creator to use Boost in Windows - c++

I created a Qt project in Ubuntu and everything went smoothly. However, I also need deploy it on Windows. It uses Boost libraries(the big problem).
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; I think I missed something. Here is what I did and downloading the lastest version:
1) ran .\bootstrap
2) then .\b2 --prefix=C:\boost install
Sadly didn't install correctly. I got only 2 folder(bin and share) but no headers.
However, here (http://nuwen.net/) I found a bundle(Mingw+Boost and other libraries). This has everything I need.
Now I think the issue is .pro file, because I have a lot of undefined references. Here is .pro file with everything I tried (some commented):
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.
If you're using msvc, then you're lucky because Boost guys did you a favour and compiled libraries for you. You can download them here: http://sourceforge.net/projects/boost/files/boost-binaries/ .
If you're using mingw (which does come in bundle with Qt), you can do this:
add mingw compiler to Windows PATH variable:
~ go to control panel and search for System;
~ add mingw's path(e.g. C:\Qt\Tools\mingw\bin) to PATH variable by appending ';' to your path(e.g.: ";C:\Qt\Tools\mingw\bin")
compile Boost libraries:
~ unzip boost archive
~ open a Command Line window, go in the unzipped boost folder, then go in folder tools/build/v2/engine
~ you have you build installer with mingw toolset: .\build --toolset=mingw
~ this will create 2 files in folder bin.ntx86 or something similar; copy the files bjam and b2 in the unzipped boost folder;
~ 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/)
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.
when build has finished, you can now link the library in Qt. To do this you need to modify .pro file. First you'll have to tell Qt where are headers are located, and you do so by adding:
INCLUDEPATH += path_to_boost_folder, e.g. : 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_system-mgw48-1_54.a"
after modifying the .pro file, run qmake, then rebuild.
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.
Building the library from the root folder is easier (Building Boost 1.52 with MinGW):
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. 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
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"

Related

Boost-Build: Building windows executable from linux

I have a c++ codebase that I need to build both windows and unix versions of. It is important that the windows executable work without cygwin or similar installed. Oh, and I'm trying to achieve this from ubuntu.
I've been trying to figure out how to make boost-build take care of it, but have so far come up short.. For simplicity assume this project structure:
root/
|- src/
| |- core/
| | |- number.cpp
| | |- number.hpp
| |- main.cpp
|- jamroot
In an attempt to make boost-build produce windows binaries as a first step, I create a user-config.jam file in my home directory containing the following:
using gcc : 4.4 : i586-mingw32msvc-g++ : <rc>i586-mingw32msvc-windres <archiver>i586-mingw32msvc-ar ;
My jamroot file looks like this:
exe hello :
[ glob-tree *.cpp ]
: : <target-os>windows
;
But when I run bjam I get a unix executable (no extension) but not a windows executable. Renaming the application with a .exe extension and running on windows does not work. I tried various options for bjam, like bjam --toolset=gcc --target-os=windows, bjam --toolset=gcc-mingw --target-os=windows etc. but noting seems to work..
For the record, mingw is properly installed and working.. Calling the compiler manually produces correct output files.
Any ideas?
Also, how do I get bjam to build a version for each toolset listed in my user-config.jam file?
Bonus question:
Eventually, I need to link against one boost library and one custom prebuilt library. How would I go about specifying different libraries for the different target systems?
UPDATE I downloaded the script from http://mingw-cross-env.nongnu.org/ which allowed me to compile a mingw as well as boost libraries in one go, so that problem is taken care of.. I found a way to make bjam call the mingw compiler (I am at a different computer so I cannot provide the solution at this time).. The other questions are still not resolved.
Unfortunately I don't think this can be done (I've failed many times) and I think the reason is because mingw is not suppported for compiling Boost. The only way people seem to have accomplished this is to maintain a separate build environment under win32 using MS Visual Studio.
From your question it's unclear if you're using bjam to build your application, or if you're just trying to build Windows versions of the Boost libraries (.lib or .dll files) to link with your application later. In my attempts I have tried to do this the 'usual' way, in that Windows versions of the Boost libraries are compiled, then the app is compiled separately with mingw32 and linked with Boost.
Unfortunately my stumbling block so far is that I can only get two outcomes - either the build fails when compiling Boost into Win32 dynamic libraries (.dll), or win32 static libraries are successfully built, but then libtool refuses to link them in with the app.
Have a look at the PKGBUILD file that Arch Linux uses to compile mingw32-boost as you might get some hints from how they do it. It seems that bjam threadapi=win32 target-os=windows is enough. Don't forget to set your prefix correctly though, so you don't overwrite your native libraries with win32 versions!
On my ubuntu box, it is as simple as
sudo apt-get install mingw
and then build
export CC=i586-mingw32msvc-gcc
make
Profit!

How to compile Boost.Process library?

So there is Boost.Process 2006, Boost.Process 2008 and most recent Boost.Process seems like 2009 by looking at sources) I need some kind of step by step guidance on how to compile that beast. Because I deffenetly do not get how to do such thing.
So For generall official Boost I understand what shall be done
With out administration privileges:
Download latest Boost release.
Unpack, extract downloaded content into some folder.
Open that folder in terminal (for example you ca open 'cmd' or 'terminal' an use command like cd absolute/path/to/directory/with/extracted/Boost than use command to show folder contents ls on Unix like OS (Mac, Linux) and dir on Windows - in output you should be capable to find boost-build.jam )
Create two folders (using command like mkdir foldername ) build-dir and install-dir
run command ./booststrap (booststrap.sh or booststrap.bat on windows)
now we can compile Boost and install it with ./bjam -j4 link=static threading=single,multi --builddir=./build-dir install --without-mpi --prefix=./install-dir
Such call will compile static libraries of Boost into build-dir. (you probably will not be capable to use Boost out from there - there will be no includes headers and a really big directories hierarchy )
Than bjam will create for us "installation" of Boost into install-dir - there will appear folder with all boost libs (static version) and includes folder with all of boost headers.
We set -j4 flag to compile on 4 cores. use -jN where N is number of desired cores to be used during compilation process.
We set --without-mpi flag because we probably do not use it.
But having Real Boost unpacked, compiled, installed in dir A (bjam is in folder B ) Having Boost.Process Download , Unpacked and Extracted to folder C how to compile any of that 3 Boost.Process releases (with out administration privileges)?
I did this once or twice and here's what I remember:
After downloading boost libs e.g. from the sandbox, unpack the lib onto the drive like you said e.g to folder C. If you open the C folder, it generally has the same folder structure as the rest of the boost source. At least this was the case in the limited libraries I tried.
From there copy the individual files and folders inside the extracted source folder into the corresponding folders in the boost source.
E.g. in the case of process
- copy C/boost/process.hpp and C/boost/process/ to boost_src_dir/boost/
- copy C/libs/process/ to boost_src_dir/libs/.
From there execute bjam (assuming the bjam executable is on your path) again in the boost root and that in my cases built everything including the new library. I remember doing this with boost log and process and can't think of having to do anything else.
The downside to doing this is that everything gets recompiled. Perhaps someone else has a better method of doing this.
As for the admin priviledges, they shouldn't matter since you're building boost in the same manner that you built the original version.

How to Link Imagemagick library to Qt(windows)

I have developed an application with mac and for one month now, Im trying to link Qt with ImageMagick on windows.
I just cant find the files and the version of Imagemagick library that need to be linked to Qt in order to make my application work on windows.
I have tried most of the libraries from here
Thats the only thing I added to the .pro file while I was developing on a mac
INCLUDEPATH += . /opt/local/include/ImageMagick
LIBS += -L/opt/local/lib -lMagick++
When I add this to my .pro
INCLUDEPATH += C:/im6/include/ImageMagick
LIBS += C:/im6/lib/libMagickWand.a
LIBS += C:/im6/lib/libMagick++.a
LIBS += C:/im6/lib/libMagickCore.a
C:/im6/lib/libMagick++.a
I get 10.000 + simmilar errors to that:
(Image.o):C:\msys\1.0\home\cristy\ImageMagick-6.6.6-0/Magick++/lib/Image.cpp:4157: undefined reference to `__gxx_personality_sj0'
C:/im6/lib/libMagick++.a(Image.o):C:\msys\1.0\home\cristy\ImageMagick-6.6.6-0/Magick++/lib/Image.cpp:4157: undefined reference to `_Unwind_SjLj_Register'
C:/im6/lib/libMagick++.a(Image.o):C:\msys\1.0\home\cristy\ImageMagick-6.6.6-0/Magick++/lib/Image.cpp:4178: undefined reference to `_Unwind_SjLj_Unregister'
For more errors check this
Has anyone tried to build and deploy an ImageMagick application using qt on windows ?
Which files do I need to link while building and which files while deploying ?
The error message tells me that you
use mingw (with qtcreator). Your
library might not work with this
compiler. You need a mingw version
of the library, probably named
libmagick.a.
LIBS += -L$$quote(c:/Program Files/ImageMagick-6.6.5-Q16/lib) -lmagick
(see the documentation about qmake Project Files
I have found that the minGW tool set is very much treated as a "stepchild" in the Windows world. I know it doesn't help your particular situation, but we had numerous problems with third-party libs while trying to use Qt with minGW. There were always extra steps, or non-existent build instructions that we had to figure out or tweak.
Once we switched to the MSVC version, all of those problems went away. Note that this doesn't mean you have to use Visual Studio (you can still use Qt creator), it just means that the Visual Studio compiler is being used. You can get the compiler for free using the Platform SDK. If this is an option, you might save yourself a lot of pain by switching now. It's unfortunate, but that is just the current status quo, at least as we discovered.
Please go get ImageMagick source package.
I can’t give direct instructions how to work with MinGW of Qt Creator, but basically following. I prefer to use qtvars.bat that comes with binary distributions of Qt to set environment.
Open Windows cmd
Set PATH to have /path/to/mingw/bin and /path/to/qt/bin before other paths
Go to directory where you have extracted ImageMagick source
read README, INSTALL and such to compile the ImageMagick (most likely just ./configure ; mingw32-make, but never be sure)
Edit your .pro file with something like LIBS += -L$$quote(/path/to/imagemagick/lib/dir) -lmagick . The lib may be in bin dir or in lib dir. See hmuelner’s answer for more information.
At this point, the configuration should be ready. Compilation at Qt Creator should work, but you can as well use this cmd windows to compile your program: go to program directory, run “qmake” and “mingw32-make”.
You cannot link against a ImageMagick++ library built with MSVC, as mingw and MSVC DLLs are incompatible for C++ libraries. You can't link a MSVC-built C++ library into a mingw project, nor vice versa. C-only libraries work fine. Also, according to this fortum thread, using builds against old mingw-versions with current mingw versions doesn't work as the exception handling changed (as you get more errors than that, I wouldn't expect that to be the only problem though). If there is no binary package for your mingw version (and I don't see any on the imagemagick website), your only option is to use a source package, as Smar suggests.
Another option of course is to install Visual Studio, download Qt for MSVC and build your project with MSVC.

Build Boost on Mac with Xcode

I've recently got acquainted with Boost library and I'd like to use it in my Xcode project. But sadly there is no HowTo or FAQ on how to do it :(
What's the sequence of actions to build and use Boost libraries in Xcode?
The easiest way I've found to do it is to install MacPorts, then you can install/build Boost via a single command:
sudo port install boost
Plus you get similar access to other open source software. The only downside I've found is that, like any other package management system, they are not always up to date with the latest version.
If you prefer Homebrew as your package manager, the command is:
brew install boost
I don't know how to use Boost from XCode (I'm not a Mac programmer), but building boost is usually done through their own build tool, bjam.
They have a guide to building boost here, and you can download the latest version of bjam here
Once it is built, you reference it from Xcode the same way you would any other library. The boost/include should be added to your include path, and the libraries in boost/lib can be referenced for the boost libs that require it.
To build boost on a mac, follow the unix variants getting started page (http://www.boost.org/doc/libs/1_39_0/more/getting_started/unix-variants.html). You won't use Xcode directly to perform the build, but once complete you can add the boost include paths and dylib's to your Xcode project.
I found that to build Boost 1.41.1 on MacOS, you need to do the following:
Download boost 1.46.1 from here: http://sourceforge.net/projects/boost/files/boost/1.46.1/
Unpack the file
Open terminal, cd to the install directory, and do the following:
chmod u+x configure.sh
cd tools/build/v2/engine/src
chmod u+x build.sh
Then go back to the install directory, and:
./configure.sh
If that runs successfully, it will tell you to run:
./bjam
That's it.. for whatever reason, I needed to set those permissions manually before it would work.
su - root
enter root password and then run below as root
/opt/local/bin/port install boost
If you have never logged in as root or forgotten your password, here are the steps to reset root password
http://support.apple.com/kb/HT1528?viewlocale=en_US&locale=en_US
For most of the boost libraries, there's nothing to build, it's all in header files.
The remainder of the instructions are here.
Currently I'm very happy with using Pete Goodliffe's script which builds a framework from the Boost source package for both iOS and Mac. Drag and drop it into a project and it works!
There are multiple versions of the script out there. Here's one:
https://gist.github.com/faithfracture/c629ae4c7168216a9856/61be257e1c0839c85743777d0687becad9913bf7
Elaboration of Ferrucio's answer:
Install Boost using MacPorts (sudo port install boost) or Homebrew (brew install boost).
Find the path to the Boost header files (it should be in /opt/homebrew/include if you're using Homebrew).
Add the path to System Header Search Paths in the Build Settings of your Xcode target.
IMPORTANT NOTE: If you add the path to User Header Search Paths instead of System Header Search Paths, as other users suggested, then your code will fail to build, since the Boost files use angled-includes (#include <boost/filename.hpp>) to include each other. Angled-includes are only for including system library headers, and thus they only work if Boost is in the System Header Search Paths.
You can read about the difference between angled-includes and quoted-includes here.

Boost 1.37 pre-built for MSVC

I can't find a pre-built set of MSVC++ libs for Boost 1.37.0, only the source. I don't understand how their weird build system works... are there any places I can find a download of a visual studio project or something?
The BoostPro Computing folks maintain the Boost installer for Windows but it usually take a few weeks for them to put new versions online. It's not yet up for 1.37.
There's no Visual Studio solution (remember, Boost targets many platforms) though there is an effort to also support building Boost with CMake. I'm not sure how far along they got for 1.37 but I believe it's still early days for this process.
However the standard build system isn't that weird! Start by downloading bjam for your platform (look for a suffix of 'ntx86' for Windows) and installing it somewhere in your path (C:/Windows/System32). Then download the source, uncompress it and run the build system from the command line. It'll look something like this for Visual Studio users:
bjam --build-dir="C:\boostsource" --toolset=msvc --build-type=complete stage
This is lifted pretty much from the Getting Started Guide which goes into much more detail. The build-dir is not needed if you're current directory is the root of the source.
After waiting a couple of hours for everything to build ('complete' means that it'll build debug, release, single/multi threaded, static/dynamic, static/dynamic linking to the runtimes - and combinations) you'll end up with all of the libs in a 'stage/lib' directory.
Finally you need to tell Visual Studio where to find the headers and libs. Go to Tools->Options->Projects and Solutions->VC++ Directories. Add an entry for "Include files" (like "C:\boostsource"). Add an entry for "Library files" ("C:\boostsource\stage\lib").
I've got a build of 1.37 (VC 7.1, 8, 9) on my website, help yourself.
http://boost.teeks99.com/
(Update... 1.38 is up there as well)
(Another Update, 1.39 is now there)
(1.40 is up)
(1.41 is up, a bit late)
It seems complicated, but building Boost is really not that bad. First you need to download the bjam tool (SourceForge is a good source). Make sure bjam.exe is in a directory in your PATH.
Go the the root of your unzipped Boost download (e.g. C:\Boost_1_37_0)
Type bjam --help to get a list of all your build options.
I use the following command to build everything, you can customize it to suit your needs:
bjam --prefix=C:\boost --build-dir=C:\build --build-type=complete install
The results will be placed in C:\boost and you can delete C:\build.
Building it isn't difficult.
They have a fairly good expanaltion of the default process here:
http://www.boost.org/doc/libs/1_37_0/more/getting_started/windows.html#or-build-binaries-from-source
Download bjam (from sourceforge, there are links from the boost website), as well as the boost sources, make sure bjam is accessible from the boost dir, cd to the boost dir, and run something like the following:
bjam --build-dir= --prefix-dir= --toolset=msvc --build-type=complete install
where is an temp dir where it can store intermediate files, and is the final install location. There are all sorts of other options you can play around with, and not all of them are documented very well, but the basics are fairly simple.
For more help, you can run bjam --help from the boost source dir.