I want to use the boost library in a c++ project I'm doing in emacs on linux, but I am having troubles getting it to work. I don't want to actually install it on my machine. I want to be able to use the regex part of boost. I want to be able to tar my source files and send them to another computer (that is likely not to have boost installed, nor will I be able to install it) and be able to compile my project. I have tried using the make file in the regex folder and made both a .a and .so, but I can't get it to compile when linking the library and setting the includes to the boost folder (I have tried multiple folders in the boost directory as well--many of them recommended by Google, but to no avail). I keep getting a "cannot find regex/config.hpp" error.
Is there anyway to include everything in one file like a .so or .a and get it to work this way? I am okay with including the regex folder itself as well, butt...
If I were to do it this way would I have to include the whole boost folder with my project anyway? That might be doable, but I don't want my tar file to be that big.
why not just listing boost as a dependencies and let user install it ?
If not, use Boost bcp to extract regex and its dependencies to a standalone library.
At first you need to build regex library in boost. Without this library you can't use
boost.regex.
Related
I am trying to include, the boost::filesystem library into a project.
The project has to run on different architectures, so I don't want to link to the boost libraries installed on my ubuntu machine.
Most of boost is header only, so I would just have to include it and not worry about building it. But the filesystem library is NOT header only and I have to build the binaries for it.
Doing that would be easy, just pass in the header using the -I flag, and during the linking state, pass in the location to search for the binary using -L and specify the library using -l.
But I don't want to use the system headers and binaries.
So I am keeping a copy of the boost::filesystem headers within my project, using the bcp tool that boost provides.
I am able to do this, and I have a subdirectory lib/fs/boost/filesystem.
When I try to build a cpp file, dependent on filesystem, the compiler is able to find the headers and everything works.
But during the linking state. It cannot find the binary and the build fails.
So how do I build the boost::filesystem ?
1) I found the bootstrap.sh and b2 way to do it. I am not sure how to use it with the bcp tool though. I was building the library from the boost root.
But a disadvantage this this approach, is that I am complicating things. Before running my makefile, I will have to run bootstrap and b2 to get the binaries. It doesn't seem clean and I would like to avoid this.
2) Is there a makefile rule that I can use to build the boost::filesystem. The project is build using a makefile, and if I could specify a rule to build the filesystem, and then link the resulting binaries, it would be great.
I searched online and I couldn't find a makefile to build a boost library. Can you point me at where I could find such a makefile ?
The question is verbose, but I am just doing it to make sure I am not making any wrong assumptions.
Thanks a lot.
I've downloaded, extracted, and compiled the Boost libraries (including the separately compiled libraries). I've used their install procedure a couple times now but I can't seem to get it to do exactly what I want. Right now, when I install Boost after compiling it goes to
C:\Boost
This is fine. The compiled libs go to
C:\Boost\lib
which is also fine. The problem I have is with the installation of the precompiled headers. They got put at
C:\Boost\include\boost-1_54\boost
Is there a way to use the Boost build system and install tools to set the precompiled headers to be installed to just
C:\Boost\include
and not have the Boost version number be a part of that folder hierarchy?
I don't plan on using multiple versions of Boost at the same time so I don't have a use for actually having that version number. I realize I could move them manually after the install is complete, but I wanted to see first if I've overlooked or misunderstood something about Boost's build system.
--layout=system removes the versioned subdirectory from the include path (as #IgorR. pointed out).
"Removing that second boost in the path" is a bad idea. In a respectable OS (cough...), the include files for various libraries are supposed to co-exist in one common include directory, hence the boost subdirectory to avoid clashes. Boost headers are therefore habitually referred to as e.g. #include <boost/any.hpp>, i.e. including that boost/ subdirectory.
This is done both by third-party software using Boost, and by Boost itself. If you remove the second boost from the path, you would end up with C:\Boost\include\any.hpp, and any Boost-using software won't compile as not even Boost could find its own includes.
How can I use libcurl with my project without actually installing it or curl on the system?
I want to make my source-code portable, so that any developer can copy the folder with all sources and other files, run make and compile the program without the need for system level installations.
I am looking for (probably separate) solutions for Linux and for Windows (dll?). If it is possible, provide some standard/official solution and not hack (I'd like to be educated about linking third party libraries)
I've used it on Windows using Visual Studio, all you need to do under Windows:
Download the source
Using CMake generate the project files (when using Visual Studio).
Build the libraries, 3 files will be built: libcurl.lib, libcurl_imp.lib and libcurl.dll
Include curl.h in your project and add the paths to your .lib files
Build your program, put libcurl.dll in the executable folder and it will work.
On Linux it should be a similar process, build the libraries and include them with your source.
You probably want to build a static library out of libcurl and link agains it. Should be pretty straightforward and the process is almost identical on every OS.
I have successfully installed boost, compiled binaries, and built bcp. I have also been able to extract the regex library using bcp. After doing this, I found a gcc_gen.sh script and bunch of makefiles under
my_exported_boost_regex/libs/regex/build/
and used one of them to make
my_exported_boost_regex/libs/regex/build/gcc/libboost_regex-gcc-1_43.a
This is the library I use in my code and everything works great.
Now I want to do the same thing for program_options but after I extract all the files using bcp, I'm confused as to what to do next. The only file available under
my_exported_boost_program_options/libs/program_options/build/
is Jamfile.v2 and I can't for the life of me figure out how to use that to build the binary. It seems to me something is missing here.
Appreciate your help.
Thanks,
J
I finally figured out that I have to include "build" in addition to my libraries of interest in the bcp call like this:
bcp program_options build ../my_exported_boost_program_options/
This apparently places the appropriate bjam config files in the exported dir and I can then call bjam from that directory and build my exported libs.
J
you have to build boost from toplevel directory with bjam. Please refer to the Getting Started Docs
I'm trying setup a subset of boost and get it properly compiled using bjam, however I'm not getting the result I'm looking for. I'm working on windows using boost 1.37.0.
Let's say I want the libraries smart_ptr and filesystem built/installed. I intentionally chose a header only library and one library needing to compile a library. I want them to be built into a directory structure similar to the one I would get if I built a complete boost installation with bjam (i.e not specifying any --with-libraryX) but of course without all the libraries I'm not interested in.
My first approach was to use the --with-filesystem --with-smart_ptr in bjam, however it seemed like it didn't recognize smart_ptr (I tried smartptr and smart-ptr without success). I guess this is because it's a header only library.
When I removed it and only had --with-filesystem it seemed to copy ALL libraries header files to the install path and only build the libraries for filesystem. The library building behavior was the one I hoped for, but I got tons of header files for libraries I'm not interested in installed in my boost directory.
My second approach was to use bcp to copy the relevant projects. This did work out in the sense that I only got the projects I cared about (and their dependencies). However they didn't provide any make files for building the libraries that was copied. This means I would need to setup projects files for all the libraries that are not header only and manually build them.
So my question is basically, is there a way of selectively building boost that only copies the headers for the libraries I'm interested in and only building library files for the non header only libraries I'm interested in (and the boost libraries they are dependent on course)?
There are probably tons of manual/scripting based solutions for this, but if I could get something running only using bjam would be way more useful for me since adding new libraries or upgrading to a new boost version would be very simple.
EDIT:
Added the complete command line for the first approach:
bjam install --prefix=c:\temp\boostsmall
--build-dir=C:\temp\boostsmalltemp --layout=system
--with-filesystem variant=debug link=static threading=multi
runtime-link=static
Changed scoped_ptr to smart_ptr
Solved it.
The bcp solution had make files for the projects, however I needed to copy the tools directory and the root of the boost directory to the place I copied all my libs to get things up running.
Great question! This is an issue I have recently managed to figure out, I think.
I already had the full Boost libraries installed, including the ones requiring separate compilation.
I managed to create a subset of the Boost libraries (regex) for a particular application I was working on using the following steps:
First ensure the bcp executable is installed in the first place. In your Boost root folder, navigate to the tools/bcp folder and run the bjam.exe in here. For me this created the bcp executable in [Boost path]\bin.v2\tools\bcp\msvc-10.0\release\link-static directory:
Then create the folder where you would like the Boost subset to reside. This might already be a folder for a Visual Studio project you are working on.
Run the bcp exectubale you created, making sure to include the libraries you wish to include, as well as the location of the boost root directory and the destination folder. Observe how the required Boost components (eg for regex) have been included in your destination folder.
bcp.exe regex --boost="C:\Program Files\boost_1_55_0\boost_1_55_0" C:\Projects\RegexProject\BoostLite
In your Visual Studio project set the Additional Include Directories and Libraries to point to the 'Boost lite' folder that was created.
One final thing - which I think is described previously - I needed to go to my regular Boost folder setup and copy the required stage/lib folder containing all the lib files needed for the subset version and copy them here, just a few regex-related lib files in my case.
I found that this worked for me. Any feedback from other persons experiences would be appreciated.
A blog posting describing the same thing can be found here.