Avoid including path to BOOST into exe - c++

We are working on a project written in C++ using BOOST, and the project is being built in Visual Studio. Inspecting the project build (exe file) I've discovered there is an entry of path to BOOST (on a build server). So, I guess it's there due to the __FILE__ macro.
EDIT: It's Release configuration with no debug information.
EDIT2: The following command is used for building BOOST:
b2 --toolset=msvc-10.0 --stagedir=./stage/2010/win32
address-model=32 variant=release
threading=single,multi link=static
runtime-link=static debug-symbols=off
Our customer doesn't want the path being there, so how to avoid absolute path including?
Regards,

You should use BOOST_EXCEPTION_DISABLE preprocessor definition

Related

How to build boost required modules only?

I just started compiling boost C++ libraries. With the following commands I issued it is building whole of the boost libraries, which is time consuming, and is not necessary for my need.
Just unpacked the boost_1_49_0.7z archive and from Visual Studio 2010 command line tool I ran bootstrap.bat and it created the b2 executable.
Using this executable I ran b2 --toolset=msvc-10.0 --build-type=complete architecture=x86 address-model=64 stage to build the libraries.
At this moment all I need is the "signals" module to be built.
What switch commands need to be supplied to the bootstrap created executable to compile and build only those specific libraries?
b2.exe --help outputs the following.
--show-libraries Displays the list of Boost libraries that require
build and installation steps, then exit.
--with-<library> Build and install the specified <library>
If this option is used, only libraries
specified using this option will be built.
Also is possible to use the -jX option to compile BOOST in X processes in parallel.

Linker error LNK1104 with 'libboost_filesystem-vc100-mt-s-1_49.lib'

During the process of linking my program to the boost::filesystem module in release mode I get the next error:
error LNK1104: cannot open file
'libboost_filesystem-vc100-mt-s-1_49.lib'
However, in the boost\stage\lib directory I only have the next libraries referred to filesystem module:
libboost_filesystem-vc100-mt-1_49.lib
libboost_filesystem-vc100-mt-gd-1_49.lib
My questions are:
Why does the VC++ is asking for 'libboost_filesystem-vc100-mt-s-1_49.lib?
Which compiler/linking properties should I change to get the compiler to ask for libboost_filesystem-vc100-mt-1_49.lib?
UPDATE: My VC2010++ solution has 2 projects that include the previous boost library: x is a library and y (the main program) which invokes to x.
When I build x with Configuration type=Static library and RuntimeLibrary=Multi-threaded (/MT), it is ok.
When I build y with Configuration type=Application (.exe) and RuntimeLibrary=Multi-threaded (/MT), it issues the error I indicated, if I change to Configuration type=Static library it builds ok, but my main program has .lib extension and not the expected .exe.
You are using /MT or /MTd option in C/C++/Code Generation/Runtime Library which require static library, boost default build with shared library output. You can switch Runtime Library to /MD or /MDd. An other option is recompile boost with static library output and you'll get 'libboost_filesystem-vc100-mt-s-1_49.lib'..
I had a similar problem with a recent project (inherited from a long legacy).
Here is a "poor man's" solution to this issue:
Rebuild the boost libraries with all variants, to be sure that you have the correct variant for your needs.
Run:
.\b2 --build-type=complete
Note that the boost build time will obviously be longer with this option.
This is not an elegant solution, but I didn't have time to mess about figuring out which exact option I needed for my project, so I just built them all.
You can paste the following characters into you control console (win+r----cmd , then go to boost src directory , find the bjam.exe)
ps:double click the bootstrap.bat can get bjam.exe
bjam --toolset=msvc-1.0 --stagedir=./lib_x64 --builddir=./ address-model=32 link=static variant=release runtime-link=static threading=multi stage debug releasde
libboost_filesystem-vc100-mt-s-1_49.lib
"link=static" correspond to -s-
"threading=multi" correspond to -mt-
"runtime-link=static" correspond to lib prefix
"variant=release" make sure libboost_filesystem-vc100-mt-s-1_49.lib don't contain -gd-
The boost libraries that you have in your boost\stage\lib directory are linking dynamically to the standard C++ libraries. See the following post:
boost lib build configuraton variations
Your code is linking statically to the standard C++ libraries, hence a mismatch. Try linking your code dynamically to the standard libraries. (Project Settings->General->Configuration Type)
run below command to rebuild boost in static in VS2013 x86 Native Tools Command Prompt.
b2 -link=static
Add your linker library paths in your project link path in VS.
Then, rebuild your project, error gone.

BOOST Version 1.46.1 with Visual Studio 2010 P.E

I'm trying to run some simple examples with Boost and I'm continuously running into this error and I have tried to compile this but I haven't been able to create "libboost_system-vc100-mt-gd-1_46_1.lib".
I keep ending up with this issue:
error LNK1104: cannot open file 'libboost_system-vc100-mt-gd-1_46_1.lib'
Anyone encounter this error before? How do you compile this properly with NMAKE because it keeps telling me it's bulding "boost.regex without ICU / Unicode Support" which is giving it a "fatal error U1073 and tells me it doesn't know how to make "../src/c_regex_traits.cpp".
Sorry if this is a jumble it's just a lot of information that's getting more and more confusing to me.
Your boost is not properly built or installed. Please follow the instruction on how to install boost.
You need to build the boost libraries first.
To do this, open command line & go to boost root eg C:\dev\boost\1_46_1.
Depending on whether you want to build for 64bit or 32bit applications, type
(x64):bjam toolset=msvc address-model=64 variant=debug,release link=static threading=multi runtime-link=static,shared stage
(x86): bjam toolset=msvc variant=debug,release link=static threading=multi runtime-link=static,shared stage
to start compiling. Be patience while boost is building, it takes a lot of time. When building is complete you can find the library files in "stage\lib" folder.
Also note that you can delete the folder "bin.v2" once building is complete.
Now you need to point your VS2010 project to those libraries. Modifying part of mlimber's answer:
In VS2010, right-click on your project, select Properties and then go to Configuration Properties -> Linker -> General. Look for "Additional Library Directories" in the middle of the list, and add C:\Program Files\Boost\boost_1_46_1\lib (or whatever) there.
Another way to do this is the following
In VS2010, right-click on your project, select Properties and then go to Configuration Properties -> VC++ Directories. Look for "Library Directories" in the middle of the list, and add C:\Program Files\Boost\boost_1_46_1\lib (or whatever) there.
Apart from the above, one could also download from
http://sourceforge.net/projects/boost/files/boost-binaries/1.46.1/
the necessary libraries (including the file missing).
While trying to build Pion network library, I ran into a very similar problem since Pion has dependency on Boost library.
My Boost build was built using boostrap and bjam, and not BoostPro.
The error I got was this: LINK : fatal error LNK1104: cannot open file 'boost_thread-vc100-mt-gd-1_46_1.lib'
When I looked at C:\OpenSource\boost_1_46_1\stage\lib directory, I saw every file name started with libboost_ and not boost_. The file boost_thread-vc100-mt-gd-1_46_1.lib was clearly missing. That made me suspicious that not all boost libraries were built by bjam. After a little research, I reran bjam with the option --build-type=complete
Now I noticed that it started creating lib file names starting with boost_. Not to mention, Pion library could now compile successfully.
Hope this adds some clarity to this thread.
Or alternatively to ybungalobill's suggestion use the installer from www.boostpro.com.
In the installer you must just select the boost versions for msvc 10 and after installation update your visual studio include and lib directories in the VS2010 property sheets to point to the boost include and lib directory.
I take it that you used the BoostPro installer, but which library types did you install -- header only, static linking, DLLs, everything?
Assuming you did everything, then the problem is probably that you don't have the path to boost in your library paths. The problematic file name starts with "libboost" which tells me you're trying to use the statically linked version, which is fine. You should add the library path to your Makefile or project settings for all build configurations. It's probably something like C:\Program Files\Boost\boost_1_46_1 (for the newest version on a 32-bit version of Windows).
In VS2010, right-click on your project, select "All Configurations" at the top, then go to Configuration Properties | Linker [or Librarian if you're making a library] | General. Look for "Additional Library Directories" in the middle of the list, and add C:\Program Files\Boost\boost_1_46_1\lib (or whatever) there.
Do that for each project in the solution that uses Boost libraries that are not header-only.
For a Makefile, you'll have to locate the library paths and add Boost to it similarly but by hand.

Do i have static or dynamic boost libraries?

I have ran bjam.exe --build-dir="C:\build-boost" --build-type=minimal msvc stage
and now I have libraries .lib with these headers, for example
libboost_serialization-vc100-mt
libboost_serialization-vc100-mt-1_45
libboost_serialization-vc100-mt-gd
libboost_serialization-vc100-mt-gd-1_45
I believe these should be static libraries for debug and release version. When I run the compiler with Multi-threaded Debug (/MTd) it gives an error LNK1104: cannot open file 'libboost_serialization-vc100-mt-sgd-1_45.lib' It is looking for one with -sgd
where am i going wrong?
Something that is kind of confusing is there are two 'static' options for building boost with MSVC.
B2.exe takes the option link=static which tells boost that you want to link it (boost) statically. If you are compiling your VC project with /MT or /MTd you will also need to use the runtime-link=static option to tell boost that you will be linking to the VC runtime libraries statically.
It is the second runtime-link=static which puts the -s in the .lib name.
My command line for building boost was
b2.exe --toolset=msvc variant=release link=static threading=multi runtime-link=static stage
You have the dynamic versions. The static ones are delimited by having the "s" in the name. Make sure you specified link=static on the bjam command line. If not, you'll have to rebuild to make the static versions.
See Boost getting started windows section 6.3 naming and section 6.1 on Unix naming
For static libraries there should be a s in there e.g. -sgd so you have dynamic libraries
here is how i break it down
libboost_serialization-vc100-mt-sgd-1_45.lib
lib- if boost library starts with lib then its a static library , shared library do not start with lib prefix. Also static library will have a '-s' in the name.
mt- multi-threaded , obtained by specifying threading=multi when you ran bjam or b2.This is the default threading.
g- use debug libraries for building the code
d- build a debug version of your code
So your compiler is searching for multi-threaded static debug library(mt-sgd) as you ran with /MTd(Creates a debug multithreaded executable file using LIBCMTD.lib). I guess by default it must be searching for static library. If you want a dynamic library, insert these lines in your code or define a macro
#define BOOST_ALL_DYN_LINK
Please check this document:
http://www.boost.org/doc/libs/1_45_0/more/getting_started/windows.html#library-naming
There you can find the meanings of all letters and how you can build the boost accordingly also...

Building Boost for static linking (MinGW)

I'm building Boost (I'm using System and FileSystem) for MinGW using bjam:
bjam --toolset=gcc stage
And it builds fine, but I want to be able to statically link to it (I have to have a single file for the final product) so I tried:
bjam --link=static --toolset=gcc stage
But I get the same output. Any ideas?
edit second question in a row I've answered moments after posting :p guess I'll leave this up here for others though.
bjam --build-type=complete --toolset=gcc stage
Will build both dynamic and static for sure.
I think link is a property as opposed to an option for bjam. That means that there should be no -- before it.
This is my command line for building only static libraries (visual c++ though):
bjam install --toolset=msvc variant=release link=static threading=multi runtime-link=static
Mapping that to your original build command I would say it should look something like this:
bjam --toolset=gcc link=static stage
or perhaps:
bjam stage --toolset=gcc link=static
Try running
bjam --help
for more info on properties and options for bjam.
Just want note that with the newer boost (Feb 2011) you need to build bjam as well now.. for some reason the current downloadable bjam doesn't work cleanly.
So first:
cd ...\boost_1_45_0\tools\build\v2\engine\src
build.bat mingw
Youll need to add bjam to the PATH (from control panel, not just on the cmd prompt). Then
cd ...\boost_1_45_0\
bjam --build-type=complete --toolset=gcc stage
My setup is Vista, Boost 1.45, MinGW 4.5, and building from cmd.exe not msys.
http://code-slim-jim.blogspot.com/2011/02/boost-in-vista-using-mingw-and-cmdexe.html
I have not built this myself in MinGW but I believe your first build will output both dynamic and static libraries and the second only static ones, so if you did not clean the build directories in between builds it will probably look the same.
When you write "I have to have a single file..." do you mean you need a single library containing all boost libraries? If so, I suspect you may have to 'ar' them together yourself.
I use the following command line to build both the statically linked as well as the dynamically linked versions of boost:
bjam "-sBUILD=debug release <runtime-link>static/dynamic <threading>multi" stage
This is done with visual c++ on windows YMMV.