Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Including Relevant Boost Libraries with C++ Source (Using Visual Studio)

I have a project I'm working on (for school) that I'm digging into the Boost libraries for the solutions. I need some way to distribute the required Boost source code with my application so that it can be compiled without the libraries being installed on the system doing the compiling. (School computers lack just about anything you can mention. The school just installed CVS last year. But they do have VS2005)

Note: I'm using Visual Studio 2005 on Vista. I have Boost 1.34.1 on my system I used the automatic installer. The documentation I've come across says something about using BCP command but that command doesn't seem to copy anything. (I'm using absolute path to call BCP so I don't end up calling the wrong command.)

Edit: I am trying to use the RegEx libraries.

Edit: The command I'm using for BCP is: "c:\Program Files\boost\boost_1_34_1\bin\bcp.exe" boost/regex.hpp regex\

And it returns: no errors detected

like image 968
epochwolf Avatar asked Sep 28 '08 13:09

epochwolf


People also ask

How do I link my Boost library to Visual Studio?

6.1 Link From Within the Visual Studio IDE Right-click example in the Solution Explorer pane and select Properties from the resulting pop-up menu. In Configuration Properties > Linker > Additional Library Directories, enter the path to the Boost binaries, e.g. C:\Program Files\boost\boost_1_55_0\lib\.

How do I add a Boost library?

In the properties dialog, select "Configuration Properties" and then "VC++ Directories". You will need to add the Boost include path to the "Include Directories" list. If you're using all header-only libraries then you're done. Otherwise, you will need to add the Boost library path to "Library Directories".

How do I install Boost from source?

Build boost from sourceDownload and extract Boost into any directory. Switch to that directory. Prepare the installation, selecting only the libraries that need to be built (this does not affect the header-only libraries). Select a prefix to install Boost to.

How do I use Boost code in C++ Visual Studio?

Create a Boost. cpp file for your tests, right-click on the project node in Solution Explorer and choose Add > New Item. In the Add New Item dialog, expand Installed > Visual C++ > Test. Select Boost. Test, then choose Add to add Test.


3 Answers

Based on your comment that you're using regex, here's what you do: download the 'normal' boost distribution zip file. Unzip it somewhere. Go to libs/regex/src. Copy and paste all the .cpp files in that directory to your project directory. Add them to your Visual Studio project (right-click, 'add' -> 'existing item'). Then go to boost/regex and copy everything in there (the header files) to your project directory (including the subdirectories). Change all the includes in your own .cpp and .h files from #include to "regex.hpp" so that it includes the headers from your local directory and not those that were installed system-wide. Make sure to remove the system-wide include path from your project settings like I said in my last post.

Then, compile your code. You'll get a number of 'missing include file' errors because regex depends on other boost libraries. Repeat the whole process: go to boost/xxx where xxx is the library that regex is looking for. You can deduce the library from the error message. Copy everything that the compiler asks for to your own project directory. You may need to fiddle a bit with your directory layout before it works. It's really a step by step approach, where every step is the same: identify the missing file, copy it over, see if that include is found and fixed, and continue with the next step. This is boring work I'm afraid.

You could automate this all with bcp but for a one-off project like a school project I wouldn't bother; only if you think you'll have future projects that will require you to deliver a self-contained zipfile.

like image 147
Roel Avatar answered Nov 09 '22 17:11

Roel


Try calling bcp with this command:

"c:\Program Files\boost\boost_1_34_1\bin\bcp.exe" --boost="c:\Program Files\boost\boost_1_34_1" regex regex

--boost tells bcp where boost is installed, the first regex is the name of the modules, the second is the destination directory.

Oh, and if you haven't already noticed, there are Visual C++ makefiles in libs\regex\build\.

like image 34
Daniel James Avatar answered Nov 09 '22 17:11

Daniel James


This seems a bit odd to me. If you are distributing source code, then the people you are distributing to should be able to install boost. Then if they already have boost, there is no duplication and confusion, or if they do not and you need a built library, they will build the correct library for their system. If the people you are distributing are not up to installing boost, then I would suggest distributing binaries in an install package to make it as easy as possible for them.

like image 1
ravenspoint Avatar answered Nov 09 '22 16:11

ravenspoint