linking to boost with visual studio 2013 - c++

I'm trying to link to several boost libraries (the ones that need to be compiled) in visual studio 2013 and am having trouble doing so.
I've installed the boost files by runing from the command line
boostrap.bat
and
b2 --toolset=msvc-12.0 --build-type=complete architecture=x86 address-model=64 stage
so that the libraries are in C:\boost_1_56_0/stage/lib
In my project I go into configuration properties>c/c++>General>Additional include directories and include C:\boost_1_56_0 and include headers using for example
#include<boost/serialization/vector.hpp> among others
I then go to configuration properties>linker>additional library dependencies and include C:\boost_1_56_0\stage\lib
I am now aware that boost uses auto linking so I ensure that there are no attempts to directing link to the boost libraries in configuration properties>linker>input>additional dependencies
However I still get (many) linker errors of the following type:
error LNK2001: unresolved external symbol "public: void __thiscall boost::archive::detail::basic_oarchive::end_preamble(void)" (?end_preamble#basic_oarchive#detail#archive#boost##QAEXXZ)
All the relevant questions I find concern misunderstandings of boost's auto linking facility, but I am now doing explicitly what I should be doing (to the best of my understanding). It is finding the the header files ok and the library files are where I am instructor the linker to look for them.
What might I be doing wrong?

There are tons of articles for linking boost in visual studio in stack overflow. One of them which I find minimal/complete is How to use Boost in Visual Studio 2010

I just run into similar question and share my idea with you.
You are probably compiling both 32bit and 64bit libs for boost. Thus I guess you maybe have two directories which contains the libs with the same names but built in different platform,like $(BOOST154_NEW_HOME)\lib_x64 and $(BOOST154_NEW_HOME)\lib_x86. You should have included both paths in your configuration properties>linker>additional library dependencies. Though boost are using auto_link to find out which lib you want to use, but it still confused about which lib under 32 bit or 64 bit need to be imported.
My suggestion is that you should include only 64bit boost libs directory in your configuration properties>linker>additional library dependencies.

Related

naming convention not applied for boost libraries when built using VS2010

I just built Boost 1.54 using Visual Studio 2010. I am trying to link the built libs into my program and I am facing an issue there. The built libraries do not follow the Boost naming convention. For example, I have boost_atomic.lib instead of libboost_atomic-vc100-mt-1_54.lib
. When linking my program, VS errors out with the following error:
LINK : fatal error LNK1104: cannot open file
'libboost_atomic-vc100-mt-1_54.lib'
I checked my VS project and I do not refer to this anywhere. How do I fix this? Is there a flag that will generate Boost libs with the naming convention? If yes, I can rebuild boost. If not, how do I tell Boost to pickup the libs I have?
P.S: I did try adding boost_atomic.lib to additional libraries, but it keeps asking for that specific lib( I have defined BOOST_SP_USE_PTHREADS)

Getting LnK1104 when linking to Boost pre-compiled libraries

I have built boost using the included tools and i ended up as expected with the stage/lib folder ! The lib folder contains several libraries with the following anming pattern:
libboost_*lib_name*_vc100_mt-gd-1_50.lib
libboost_*lib_name*_vc100_mt-1_50.lib
Though building a project with cl.exe i get a linker error 1104 for lib with the following pattern
libboost_*lib_name*_vc100_mt-s-1_50.lib
Any ideas ?? If on the other hand use visual studio 10 and set the stage/lib at my VC++ Direcotries - Library Direcotries, all work like a charm !
mt-s in lib name means your project is compiled with options to use multithreaded and statically linked C++ standard runtime library. Looks like your Boost build isn't configured to build such lib version, so it is missing.

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.

How to link Boost in a dependent static library

In MS Visual C++ 2010
I had a single C++ project in my solution which used boost and worked perfectly.
I then decided to convert this project into a static library and create a new project which depends on this static library.
Now, my converted static library builds without errors and warnings (compiler and linker)
but the new project compiles but does not link.
I am getting:
1>LINK : fatal error LNK1104: cannot open file 'libboost_thread-vc100-mt-1_45.lib'
As a test I added the full directory path to the linker options for this library... and then it complained about
1>LINK : fatal error LNK1104: cannot open file 'libboost_date_time-vc100-mt-1_45.lib'
I have now added complete paths to all the libraries and it now builds and run.
I am not happy with this solution because:
I don't want users of the library to
have to worry about linking in
boost.
It is messy
I know an answer would be to create a DLL but is there a way to do this statically and keep the linking at my static library level.
Edit:
If I tell the .exe linker to ignore the boost libs explicitly then it all is ok except the .exe should not have to worry about boost at all.
/NODEFAULTLIB:"libboost_thread-vc100-mt-1_45.lib" /NODEFAULTLIB:"libboost_date_time-vc100-mt-1_45.lib"
Apparently you don't need the .libs, as your exe also links without them. You seem to be using boost header-only methods and classes. So just tell boost to disable auto linking by defining the preprocessor symbol BOOST_ALL_NO_LIB in your project.
If you want to make your .lib unnecessary big by including all of boost, this question seems to hold an answer (which I never really tried myself): Linking static libraries to other static libraries
When building your library, you can include the boost libraries in yours. To do so, in VisualStudio's Librarian > General property page, list your boost libraries as Additional Dependencies.
However, there may be a problem if your clients use boost themselves, and statically link to it (especially a different version than the one you are using).
Did you build boost library? There are certain libraries in Boost that needs to be compiled. In case if you haven't done that, refer to "Getting started in Windows" on how to build the Boost library.
EDIT-1: Boost can be built both as a static and dynamically loadable (dll) libraries.
EDIT-2: If you have already built Boost, then the answer by #Daniel Gehriger tells you how to add it in VS.

Boost linker error: Unresolved external symbol "class boost::system::error_category const & __cdecl boost::system::get_system_category(void)"

I'm just getting started with Boost for the first time, details:
I'm using Visual Studio 2008 SP1
I'm doing an x64 Build
I'm using boost::asio only (and any dependencies it has)
My code now compiles, and I pointed my project at the boost libraries (after having built x64 libs) and got past simple issues, now I am facing a linker error:
2>BaseWebServer.obj : error LNK2001: unresolved external symbol "class boost::system::error_category const & __cdecl boost::system::get_system_category(void)" (?get_system_category#system#boost##YAAEBVerror_category#12#XZ)
2>BaseWebServer.obj : error LNK2001: unresolved external symbol "class boost::system::error_category const & __cdecl boost::system::get_generic_category(void)" (?get_generic_category#system#boost##YAAEBVerror_category#12#XZ)
any ideas?
I added this define: #define BOOST_LIB_DIAGNOSTIC
And now in my output I see this:
1>Linking to lib file: libboost_system-vc90-mt-1_38.lib
1>Linking to lib file: libboost_date_time-vc90-mt-1_38.lib
1>Linking to lib file: libboost_regex-vc90-mt-1_38.lib
which seems to indicate it is infact linking in the system lib.
I solved the problem. I had built 32-bit libraries when I had intended to build 64-bit libraries. I fixed up my build statement, and built 64-bit libraries, and now it works.
Here is my bjam command line:
C:\Program Files (x86)\boost\boost_1_38>bjam --build-dir=c:\boost --build-type=complete --toolset=msvc-9.0 address-model=64 architecture=x86 --with-system
#include <boost/system/config.hpp>
In my case, BOOST_LIB_DIAGNOSTIC did not show system being automatically linked in. I resolved this by simply including boost/system/config.hpp.
You need to link in the boost_system library
I had the same problem. I tried all described above, but nothing helps. The solution was simple: first I worked with an empty project and there I had linker error LNK2019. But when I created new default Win32 console application with stdafx.h, targetver.h and stdafx.cpp files everything worked. May be it will be useful for somebody, I spend two days for this
If you use boost::system in your project, you should use and appoint the x86 or x64 version of boost::system lib.
You can recompile Boost library with the following batch file. Save these to the Boost root folder and run it in CMD Windows (don't double click!):
call "%VS140COMNTOOLS%..\..\VC\vcvarsall.bat" x86
cd boost_1_60_0
call bootstrap.bat
rem Most libraries can be static libraries
b2 -j8 toolset=msvc-14.0 address-model=64 architecture=x86 link=static threading=multi runtime-link=shared --build-type=minimal stage --stagedir=stage/x64
b2 -j8 toolset=msvc-14.0 address-model=32 architecture=x86 link=static threading=multi runtime-link=shared --build-type=minimal stage --stagedir=stage/win32
pause
For more details, you can see this article: https://studiofreya.com/2015/12/19/how-to-build-boost-1-60-with-visual-studio-2015/
I came to the question via searching for the linker error plus CMAKE, so I'm adding this comment here in case anyone else finds this question the same way.
It turns out that the linker error in my case was due to an errant:
add_definitions(-DBOOST_ALL_DYN_LINK)
in the CMakeLists.txt, which is fine for Unix, but not Windows in my case. The solution is not use that define on Windows.
I needed both versions and used stage target, so I used --stagedir=./stageX86 for x86 version and the default ./stage for x64
I also came here from for this linker error plus CMake, but in my case it was the fact that CMake by default will try to build with 32bit by default. This was fixed by specifying -Ax64
cmake -Ax64 {path to CMakeLists.txt}
None of the methods worked for me given before in this thread.
Then I checked the files inside boost system folder and tried below #define
#define BOOST_ERROR_CODE_HEADER_ONLY
The linking error is solved after using this.
In my case, I resolved this by moving the boost include dir from
Project -> Properties-> VC++ Directories -> Include Directories
to
Project -> Properties-> C/C++ -> General -> Additional Include Directories
, and moving the boost lib dir from
Project -> Properties-> VC++ Directories -> Library Directories
to
Project -> Properties-> Linker -> General -> Additional Library Directories
Maybe the error is caused by link order.