Distributing Boost.Program_options
Hello all, I'm a first time user of boost libraries and I'm finding them extremely useful. I will be incorporating their use into a number of open source research projects. I've searched the archives on how to distribute the boost source with my code. It seems the bcp tool is the way to go for this, however, I'm confused on how to use it for my purpose. I would like to keep the code as portable as possible without users needing to install additional libraries on their own. Since most of the boost libraries are all contained in header files, it seems easy to distribute. However, I always getting linking errors unless I link against a pre-built library for Boost.Program_options. Is it necessary for this library to be built first, then linked against? How could I use the 'bcp' tool to grab the needed Boost dependencies for my project? Can I use a standard make file as the users wouldn't have bjam installed? My apologies if this is covered in an obvious location. I've found the documentation to be helpful, but I haven't found what I've needed yet to accomplish this. Any help would be greatly appreciated. Best, Chris Thachuk Graduate Student Simon Fraser University Vancouver, BC, Canada
Chris Thachuk wrote:
Hello all,
I'm a first time user of boost libraries and I'm finding them extremely useful. I will be incorporating their use into a number of open source research projects. I've searched the archives on how to distribute the boost source with my code. It seems the bcp tool is the way to go for this, however, I'm confused on how to use it for my purpose.
I would like to keep the code as portable as possible without users needing to install additional libraries on their own. Since most of the boost libraries are all contained in header files, it seems easy to distribute. However, I always getting linking errors unless I link against a pre-built library for Boost.Program_options.
Is it necessary for this library to be built first, then linked against?
Yes.
How could I use the 'bcp' tool to grab the needed Boost dependencies for my project?
I don't have a pointer handy; but I think bcp docs say that.
Can I use a standard make file as the users wouldn't have bjam installed?
No. You can either distribute prebuilt binaries, or you can include both bjam and boost.build in your project, and have a shell script to build bjam and then build necessary boost library. - Volodya
Chris, There is another option that I have seen on the mailing lists, and it is the option that I use. I just plumb the Boost source files directly into my build system. Often this approach is preferred, as you can guarantee that the Boost source files are being compiled with a compatible set of flags as the code that depends on it (compatibility is notoriously difficult on Windows). Furthermore, it releases you from distributing Boost binaries with your source. This immediately gives you a more portable application. In my case, I use CMake as a build tool, and my applications compile on both Windows and Linux (32 and 64 bit) without having to distribute any binaries. I use this technique for the filesystem, iostreams, unit_test_framework, thread, regex, signals, and program_options libraries. For the most part, compiling Boost source files does not require any "trickery". If you are compiling on Windows, you probably want to define the following flags: BOOST_ALL_NO_LIB _SCL_SECURE_NO_WARNINGS WIN32_LEAN_AND_MEAN BOOST_ALL_NO_LIB disables the automatic linking of Boost binary libraries. This allows you to name the library according to your own convention and link it in manually. This is most likely a must in your case. _SCL_SECURE_NO_WARNINGS will remove some compilation warnings regarding non-ANSI "secure" functions on Windows. This is optional. WIN32_LEAN_AND_MEAN is probably not necessary for program_options. I have found that it is a necessity for using ASIO, and it is probably not a bad flag to use anyway. This is optional. The bcp tool will pull out the required headers as well as the required source files for program_options. You will want to compile all of the *.cpp files located in libs/program_options/src. I hope that this helps. Justin P.S. My CMake scripts are designed to automatically download and unzip the Boost distribution package. In my case, I do not need to include any Boost sources with my application because the build system takes care of it. On Thursday 24 May 2007 02:52, Vladimir Prus wrote:
Chris Thachuk wrote:
Hello all,
I'm a first time user of boost libraries and I'm finding them extremely useful. I will be incorporating their use into a number of open source research projects. I've searched the archives on how to distribute the boost source with my code. It seems the bcp tool is the way to go for this, however, I'm confused on how to use it for my purpose.
I would like to keep the code as portable as possible without users needing to install additional libraries on their own. Since most of the boost libraries are all contained in header files, it seems easy to distribute. However, I always getting linking errors unless I link against a pre-built library for Boost.Program_options.
Is it necessary for this library to be built first, then linked against?
Yes.
How could I use the 'bcp' tool to grab the needed Boost dependencies for my project?
I don't have a pointer handy; but I think bcp docs say that.
Can I use a standard make file as the users wouldn't have bjam installed?
No. You can either distribute prebuilt binaries, or you can include both bjam and boost.build in your project, and have a shell script to build bjam and then build necessary boost library.
- Volodya
I just plumb the Boost source files directly into my build system.
This does make the most sense for my situation. Do you just add a "boost" subproject in your top level directory?
In my case, I use CMake as a build tool, and my applications compile on both Windows and Linux (32 and 64 bit) without having to distribute any binaries.
I've now realized that as I've added more library dependencies (three in addition to boost), my simple makefile approach is becoming very tedious. I am very interested in using a build system like CMake, or boost.build. CMake looks very easy to use, but how do you avoid using bjam to build the boost libraries? Have you created a 'CMakeLists.txt' file for each boost library to replace the jam files (if so was this complicated)? Or is there a simpler approach for this?
I hope that this helps. ...
Justin
This has already helped a lot. Thank you. Chris
Chris, The best way for me to answer your question is with an example. I cleaned out my project-specific stuff and put together an example of my CMake setup (see attached zip file). I was able to test it on Linux, but I did not have time to test it on Windows (it should work). There is a configuration variable "USE_BOOST_RC". If this is set to "ON", it will download, unbundle, and build the boost_1_34_0 libraries. By default, it will download, unbundle, and build the boost_1_33_1 libraries. Of course, my script only builds a small subset of the Boost libraries, but I'm sure you get the idea. A directory named "external" will be created where the boost packages will be unbundled. The boost packages will be downloaded to "external/packages". CMake calls two python scripts to do the work of downloading and unbundling the boost packages. These Python scripts expect "unzip" and "wget" to exist on your path. If you do not want to deal with the wget, and unzip dependencies, simply place the boost package in external/packages manually, and unzip it in the external directory. FWIW, I really like CMake. I used to use SCons. SCons has more raw capability, but CMake is significantly faster. I don't like the hack I used of running an external Python script from CMake, but I was not able to get the desired result without the hack (CMake would automatically remove some of the Boost sources during the clean). Maybe a better CMake hacker can show me the error of my ways :-) In order to use one of the local boost libraries in your CMake project, you must do the following three things in your project's CMakeLists.txt: 1) Add BOOST_INCLUDE_DIR to include_directories 2) Add the library to target_link_libraries 3) Add boost-headers as a dependency Example (Using boost-thread): project(my-cool-project-using-boost-thread) include_directories(${BOOST_INCLUDE_DIR}) # Step 1 target_link_libraries(${targetName} boost-thread) # Step 2 add_executable(${targetName} ${sourceFiles}) add_dependencies(${targetName} boost-headers) # Step 3 Adding "boost-headers" as a dependency ensures that Boost is downloaded and unbundled prior to building the target. Thanks, Justin On Thursday 24 May 2007 09:44, Chris Thachuk wrote:
I just plumb the Boost source files directly into my build system.
This does make the most sense for my situation. Do you just add a "boost" subproject in your top level directory?
In my case, I use CMake as a build tool, and my applications compile on both Windows and Linux (32 and 64 bit) without having to distribute any binaries.
I've now realized that as I've added more library dependencies (three in addition to boost), my simple makefile approach is becoming very tedious. I am very interested in using a build system like CMake, or boost.build.
CMake looks very easy to use, but how do you avoid using bjam to build the boost libraries?
Have you created a 'CMakeLists.txt' file for each boost library to replace the jam files (if so was this complicated)?
Or is there a simpler approach for this?
I hope that this helps. ...
Justin
This has already helped a lot. Thank you.
Chris
participants (3)
-
Chris Thachuk
-
KSpam
-
Vladimir Prus