boost linker error wrong toolset - c++

there are many questions related to this but none so far is a solution in my case.
I built boost 1.63 libraries with VS 2017, using toolset 14.1
The command line for building boost libs is:
bjam --toolset=msvc-14.1 --build-dir="libs" --stagedir="x64" --build-type=complete stage address-model=64 threading=multi link=static runtime-link=static
The 2nd lib in the build folder is
libboost_atomic-vc141-mt-sgd-1_63.lib
My project using boost is pointing to this folder. But linking with VS 2017
and Toolset 14.1 selected throws an error:
LINK : fatal error LNK1104: cannot open file 'libboost_atomic-vc140-mt-sgd-1_63.lib'
As you can see, only the toolset in incorrect.
Is there an additional switch and where to find ? Thank you.
One comment: i built the bjam.exe with project-config.jam setting
using msvc : 14.1;
and libraries been built lightning fast: Below 20 seconds for all x64 libraries!

Boost 1.63 hasn't been made compatible with Visual Studio 2017, so there's a few things you gotta do manually to fix things. In order to make sure it picks up the correct library files, you need to make edits to auto_link.hpp, which is found in boost/config. Change these lines:
# elif defined (BOOST_MSVC)
// vc14:
# define BOOST_LIB_TOOLSET "vc140"
To this:
# elif defined (BOOST_MSVC) && (BOOST_MSVC < 1910)
// vc14:
# define BOOST_LIB_TOOLSET "vc140"
# elif defined (BOOST_MSVC)
// vc15:
# define BOOST_LIB_TOOLSET "vc141"
And then do a clean recompile of the boost libraries, and replace the original version of this file in your includes with this modified version.

Related

Build Boost Coroutine2

As this has been marked as duplicate earlier: This problem has nothing to do with the basic "How to install boost...". Boost is installed and all libraries but coroutine2 are working correctly. So this is a coroutine2 problem.
When trying to compile my project I get the following linker error:
LNK1104 cannot open file 'libboost_coroutine2-vc140-mt-gd-1_64.lib'
After checking I noticed that file was missing, even though I built boost with the following command:
b2 install --build-type=complete msvc -mt
So I tried to build it manually using the following command:
b2 install --build-type=complete msvc -mt --with-coroutine2
Something interesting happened: It built Boost.Context (which was already built by the first command) which it is built on, but no Coroutine2 lib in sight.
Now I tried to run the project on my other computer with boost 1.61 installed - and it worked flawlessly! After checking the coroutine2/detail/config.hpp (which determines which library to link against) I noticed that boost 1.61 wants to load the coroutine lib while boost 1.64 requires a coroutine2 lib...
On Boosts Getting Started page Coroutine2 isn't listed as a "has-to-be-built" library and after dissecting the config.hpp file I came up with the idea to define #define BOOST_COROUTINES2_NO_LIB which resulted in many unknown symbols...
I don't know what else I can do, please help, dear professionals :)
First of all I've found which exact cpp is generating LNK1104 error. Then I've enabled "Preprocess to a File" option to see in the preprocessed file, who's making the linking request. Then bingo!
#line 401 "C:\\libdev4\\boost\\boost/config/auto_link.hpp"
#pragma comment(lib, "boost_coroutine2" "-" "vc140" "-mt" "-gd" "-" "1_64" ".lib")
So, it's a bug in boost 1.64 auto_link.hpp
p.s. disabling the automatic linking via defining BOOST_ALL_NO_LIB in my project and setting the necessary libs manually, solves the problem.
boost.coroutine2 is a header-only library - a libboost_coroutine2-vc140-mt-gd-1_64.lib ist not created. You should check the linker flags of your project and remove the reference to libboost_coroutine2.
EDIT: remove sub directory 'build' from boost.coroutine2
I faced same issue in Boost 1.64 when building from MS Visual Studio.
With Boost 1.65 I don't face this problem anymore.
You can copy the libboost_coroutine-xxx.lib to boost_coroutine2-xxx.lib and put it in the lib path. because oroutine2 no use lib. So no matter what content in the lib make no difference .

Cannot find boost libraries with cmake

I've install boost 1.63.0 on Windows and I am trying to build with CMake (using Visual Studio 2017 as a generator). I'm having trouble getting find_package() to find my boost libraries and I can't figure out why.
CMakeLists.txt:
find_package(Boost REQUIRED COMPONENTS system filesystem thread)
Output:
CMake Error at C:/Program Files (x86)/CMake/share/cmake-3.8/Modules/FindBoost.cm
ake:1813 (message):
Unable to find the requested Boost libraries.
Boost version: 1.63.0
Boost include path: C:/Program Files (x86)/boost/boost_1_63_0
Could not find the following Boost libraries:
boost_system
boost_filesystem
boost_thread
Some (but not all) of the required Boost libraries were found. You may
need to install these additional Boost libraries. Alternatively, set
BOOST_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT
to the location of Boost.
Boost finds the includes, but not the libraries. Headers are located at:
%BOOST_ROOT%. Libraries are located at %BOOST_ROOT%/stage/lib. When I look at _boost_LIBRARY_SEARCH_DIRS_RELEASE, the first place it looks is the correct location. I've also tried hard-coding BOOST_LIBRARYDIR to that path just to be sure.
To install boost I extracted the downloaded archive to %BOOST_ROOT%, then ran bootstrap and .\b2 link=static,shared threading=single,multi. This should give me all versions of the libraries. In the case of boost:system, I have the following binaries in %BOOST_ROOT%/stage/lib%:
boost_system-vc100-mt-1_63.dll
boost_system-vc100-mt-1_63.lib
boost_system-vc100-mt-gd-1_63.dll
boost_system-vc100-mt-gd-1_63.lib
libboost_system-vc100-mt-1_63.lib
libboost_system-vc100-mt-gd-1_63.lib
I've tried enabling and disabling the following, but to no avail:
set( Boost_USE_STATIC_LIBS ON )
set( Boost_USE_MULTITHREADED OFF )
set( Boost_DEBUG ON )
Here is an interesting part. The Boost_DEBUG parameter spits out this line:
Searching for SYSTEM_LIBRARY_RELEASE: boost_system-vc141-mt-1_63;boost_system-vc141-mt;boost_system-mt-1_63;boost_system-mt;boost_system
Note the vc141 versus vc100. I think .\b2 built something for vc100. That's strange because I was running it from the Dev Command Prompt for VS 2017. I've taken a wild guess and tried to build boost with ./b2 toolset=msvc-14.1 but I get an error: *** argument error * rule maybe-rewrite-setup ( toolset : setup-script : setup-options : version : rewrite-setup ? )".
How can I ensure that I compile boost with VS2017 or MSVC141?
This thread seems related:
Version numbers for Visual Studio 2017, Boost and CMake
Check the FindBoost.cmake script that is being used. Depending on the version of CMake you use, this version of Boost may not be handled. The dependencies between libraries is set depending on the version of Boost found.
For example the latest version of the script in CMake sources on GitHub handles version 1.63. I had the problem with CMake v3.6.2 which does not handle it.
Regarding the version mismatch for MSVC I don't know, sorry.
I compiled boost, and am compiling the linking application with the same toolset. Therefore I decided that it was safe to simply rename all compiled libs from *-vc100-* to *-vc141-*. While normally I would discourage that (you could get subtle differences in the ABI), in this case I was certain that it was the same compiler and so it's clear that either cmake or b2 had a bug which created(or searched) a file with the wrong name.
After doing that, cmake not only found boost, but linked successfully.

Unable to link to boost 1.60 thread library in Visual Studio 2013 on Window 7

i am trying to use boost 1.60 thread library in my project with visual studio 2013 on window 7. Following command i used to build boost
b2.exe toolset=msvc-12.0 variant=debug link=shared threading=multi address-model=32 -j5 --build-dir=some_directory --libdir=some_directory install
Though building was successful when i add thread library in visual studio linker input option i get error saying
error LNK1104: cannot open file 'libboost_thread-vc120-mt-gd-1_60.lib'
Few NOTES::
1. Is boost directory is in include path : Yes
2. Is boost lib directory is added to additional lib directory path : Yes
3. Is boost lib dll is in application's environment path : Yes
4. Did i build boost with different version of visual studio and trying to use in different version : No, both is VS2013
5. Is boost build address model is different than application's address model : No, both is 32 bit
after checking multiple times all of the above my knowledge base ends on this :(
kindly extend it solve this problem. What else i need to check?
For anyone who gets into same problem in future..
Just make sure you have added preprocessor flag BOOST_ALL_DYN_LINK if you are using shared library version of Boost

Could not link boost file system

I use Visual Studio 2012 Update 4. I cannot build my project.
I've downloaded boost archive, extracted it to C:\boost.
Opened Developer Command Line for VS2012 and executed bootstrap.bat and bjam.exe in boost directory (took about 5 minutes).
In my project, i've added C:\boost to additional include directories and C:\boost\stage\lib to additional library directories (in build settings).
If i write in my code:
#include <boost\filesystem.hpp>
I get linkage error:
Error 1 error LNK1104: cannot open file 'libboost_filesystem-vc110-mt-gd-1_58.lib'
Project type is: Win32 application (CLR support).
Other boost headers seems to work well on other project.
What should i learn about linking boost what i am missing?
Fixed this issue by running this command in c:\boost (thanks #marom):
b2.exe --with-filesystem --toolset=msvc-11.0 --build-type=complete stage

Compiling boost with zlib

I'm compiling boost with bjam under Windows 7 (64bit-should be irrelevant)
D:\development\boost\boost_1_44\libs\iostreams\build>bjam stage ^
--toolset=msvc-10.0 link=static ^
--build-type=complete ^
-s ZLIB_SOURCE=C:\zlib125-dll ^
-s ZLIB_LIBPATH=C:\zlib125-dll\lib ^
-s ZLIB_INCLUDE=C:\zlib125-dll\include ^
-s ZLIB_BINARY=C:\zlib125-dll
But I only get
stage/libboost_iostreams-vc100-mt-gd-1_44.lib
bin.v2/libs/iostreams/build/msvc-10.0/debug/threading-multi/boost_iostreams-vc100-mt-gd-1_44.dll
bin.v2/libs/iostreams/build/msvc-10.0/debug/threading-multi/boost_iostreams-vc100-mt-gd-1_44.lib
bin.v2/libs/iostreams/build/zlib/msvc-10.0/debug/threading-multi/boost_zlib-vc100-mt-gd-1_44.dll
bin.v2/libs/iostreams/build/zlib/msvc-10.0/debug/threading-multi/boost_zlib-vc100-mt-gd-1_44.lib
but stage/libboost_zlib-vc100-mt-gd-1_44.lib is missing.
Am I compiling something wrong?
when I try running my project that worked well with boost and self-compiled boost/thread libraries I get the following error when I include the boost zlib stuff
6>LINK : fatal error LNK1104: cannot open file 'libboost_zlib-vc100-mt-gd-1_44.lib'
Does anyone know what I'm doing wrong?
I did manage to build them using the option
-sZLIB_SOURCE="C:\zlib-1.2.5"
Note there is no space after the -s and the quotes around the path.
It took me a while to get Boost to build correctly with zlib support.
The problem I ran into was that at some point zlib no longer included a gzio.c source file. The jamfile for the Boost build system (jamfile.v2) had a reference to the gzio module which caused it fail. The solution was to remove that reference before building.
I'm not sure this answer is relevant any longer, unless you're trying to build an old version of Boost. I believe the original build issue has been fixed in more recent versions of Boost.
I had the same problem (Windows 7 Visual Studio) and I believe the issue is not in how you build boost.
1) As ecotax, there should not be a space after the -s
2) When running bjam, add the flag --debug-configuration. If in the output you do not see errors and it prints out something like
notice: iostreams: using prebuilt zlib
then it has found your zlib copy, which it is good.
3) Notice that the library libboost_zlib-vc100-mt-gd-1_44.lib should not be produced.
4) When you compile your application in Visual Studio, seems that Boost.Iostreams auto-linking still wants libboost_zlib-vc100-mt-gd-1_44.lib and reports a link error.
What it worked for me (I founded googling) was to add to the preprocessor definitions the flag
BOOST_IOSTREAMS_NO_LIB
I was trying all sorts of things and had a hard time finding the correct solution for newer versions of boost (1.75.0).
All the -sZLIB_xxx switches seem to be not working anymore.
Boost Documentation just states
On Windows the zlib, bzip2, zstd and/or LZMA binaries need to be in the PATH, else they will not ordinarily be found by default, so it is always a good idea under Windows to setup the zlib, bzip2, zstd and/or LZMA toolsets in your own jamfile.
Setting path did not lead to any success, so I dig through more documentation. Boost provided jam documentation and examples are not the most helpful, so through analysis of the Conan Recipe for the Conan boost package I finally came up with this minimal user-config.jam file that does the trick for me:
using zlib : your.zlib.version :
<include>"path/to/zlib/include/headers"
<search>"path/to/zlib/library/file" ;
The minimal b2 command to execute this for me is:
.\b2.exe --user-config="path/to/user-config.jam"
Hope this can be of help to others so they don't need to waste a lot of time as I did.
For guys, who compiling, using prebuilt 'zlib'.
These steps needs to be done:
Download and build 'zlib'
Run b2.exe --with-iostreams -s ZLIB_BINARY=zlib -s ZLIB_INCLUDE=C:/Sys/zlib-1.2.7/Include -s ZLIB_LIBPATH=C:/Sys/zlib-1.2.7/Lib release
Update paths to your local installation zlib folder. This way, Boost will embed into libboost_iostreams the gzip.cpp, zlib.cpp files. No libboost_zlib will be generated.
At your source file add this lines (somewhere in stdafx.h, before including Boost.Iostream headers):
--
#ifdef _DEBUG
#define BOOST_ZLIB_BINARY zlibd
#else
#define BOOST_ZLIB_BINARY zlib
#endif
This tells that you don't want to link against libboost_zlib, but you provide precompiled zlib library instead.
At your project settings provide path to zlib.lib file.
It should compile and link now.
I took a combination of advice from other answers here and this is what I did:
Extract zlib to C:\zlib\zlib-1.2.11.
Use CMake to configure and generate MS Visual Studio 2017 project and use MS Visual Studio 2017 to build the project. I built it in place so that C:\zlib\zlib-1.2.11 now contains (in addition to previous contents) directories lib and include.
Extract Boost 1.67.0 to C:\Boost\boost_1_67_0.
(Be on drive C:)
cd \Boost\boost_1_67_0
bootstrap.bat
set ZLIB_SOURCE="C:\zlib\zlib-1.2.11"
set ZLIB_INCLUDE="C:\zlib\zlib-1.2.11\include"
set ZLIB_LIBPATH="C:\zlib\zlib-1.2.11\lib"
The following line built libboost_iostreams and it did put libboost_zlib files in C:\Boost\boost_1_67_0\stage\lib:
b2 --debug-configuration --with-iostreams -sZLIB_SOURCE="C:\zlib\zlib-1.2.11" -sZLIB_INCLUDE="C:\zlib\zlib-1.2.11\include" -sZLIB_LIBPATH="C:\zlib\zlib-1.2.11\lib"
The following line built the rest of Boost:
b2 -sZLIB_SOURCE="C:\zlib\zlib-1.2.11" -sZLIB_INCLUDE="C:\zlib\zlib-1.2.11\include" -sZLIB_LIBPATH="C:\zlib\zlib-1.2.11\lib"
Don't know if this is the most optimal way to do it, but it did build the libboost_zlib lib files.
set ZLIB_SOURCE="c:\zlib"
set ZLIB_INCLUDE="c:\zlib"
.\b2
.\bjam will not build but .\b2 will build the library: stage/libboost_zlib-vc100-mt-gd-1_44.lib