Linking with boost .lib - c++

I'm getting a link time error fatal error LNK1104: cannot open file 'libboost_serialization-vc80-mt-gd-1_44.lib' I recently downloaded boost which came with boost_serialization-vc80-mt-gd-1_44.lib but the compiler seems to be looking for one starting with libboost so i renamed it. but then it fails to find .dll at runtime. I tried to rename the dll but doesn't seem this helps.
While loading dll: An unhandled non-continuable STATUS_DLL_NOT_FOUND exception was thrown during process load

There are many different versions of each boost library: multi-threaded, single-threaded, static, dynamic, etc. The ones starting with "lib" are the static libraries, the ones without "lib" are the lib files used to link to the DLL versions. You can see this by looking at the lib file size.
If you are auto-linking boost, it means that the linker is looking for the static version of serialization. If you don't have such a file, it means you didn't build it. Another alternative is to use the installer available at http://www.boostpro.com. It allows you to select which boost libraries (static, dynamic, ST, MT, VS Version, etc) to download and install.
The other option is to disable auto-linking: see this post on the boost mailing list: http://lists.boost.org/boost-users/2005/12/15697.php

Related

Linking boost library in node native module, object file requiring alternative library version

I recently had the need to pull in the Boost Graph Library for one of the native node modules that I work on, along with boost serialization. There is a separate VS project that I do all of my development and testing for this module. The project compiles, links, and works as expected when run from the VS project.
I am having issues when I try to link the static serialization library with my module when building with node-gyp. I have included the full path to the serialization library in the libraries section of the binding.gyp file. In the object file produced from the node-gyp compiled file, the following line is causing a linker failure:
/FAILIFMISMATCH:"_CRT_STDIO_ISO_WIDE_SPECIFIERS=0"^#^Dlibboost_serialization-vc140-mt-s-x64-1_67.lib^#^Dlibboost_serialization-vc140-mt-s-x64-1_67.lib^#^Duuid.lib^#^Duuid.lib^#
The object file is expecting libboost_serialization-vc140-mt-s-x64-1_67.lib. When the build process tries to link the file, the linker spits out an error:
LINK : fatal error LNK1104: cannot open file 'libboost_serialization-vc140-mt-s-x64-1_67.lib'
However, boost built libboost_serialization-vc141-mt-s-x64-1_67.lib which is a different version than what the object file is expecting. I have tried to build the version that the object file is looking for, but I cannot seem to get boost to do so (each time I try, it skips all of the targets, even though I am specifying an alternative toolset).
How can I change the library version that the object file is expecting?
When I tried to build the "right" version of the serialization library, I had been using toolset=msvc-140. It should have been toolset=msvc-14.0. Sometimes I am dumb.

Missing boosts filesystem lib after build

I have the latest version of boost (1.58). After building it via command line on windows:
bootstrap
.\b2
I add boost dir to path and boost/stage/lib to lib path.
I add #include to my code and when I compile I get an error saying:
Error 1 error LNK1104: cannot open file 'libboost_filesystem-vc120-mt-sgd-1_58.lib' E:\SourceControl\zombiegame\ZombieGame\Projects\Windows\LINK ZombieGame
I'm not including any lib myself so guessing boost is doing this via the code, but this file doesn't exist in the stage/lib path.
The closest I have is libboost_filesystem-vc120-mt-gd-1_58.lib but you can see it's -gd- not -sgd- like it's asking for. What am I missing here?
You are probably using a configuration that is not provided by boost. Boost build its libraries with different settings for Debug/Release and (here I think is the point) for Runtime library (static lib/dynamic dll/single threaded/multithread). From the names I would guess you have a static or single threaded config. Try to change that one and you should find one of those provided by boost build.

Interesting LNK1104 error when using the static version of boost::filesystem

I'm trying to test out some code which makes use of boost::filesystem for various things.
I built the static version of boost 1.51 for vc11, and the intended libraries came out as expected.
Here are the flags I used:
b2 --with-filesystem --build-type=complete --build-dir=.\build link=static runtime-link=static
And here's the list of files it generated:
libboost_filesystem-vc110-mt-s-1_51.lib
libboost_filesystem-vc110-mt-sgd-1_51.lib
libboost_filesystem-vc110-s-1_51.lib
libboost_filesystem-vc110-sgd-1_51.lib
libboost_system-vc110-mt-s-1_51.lib
libboost_system-vc110-mt-sgd-1_51.lib
libboost_system-vc110-s-1_51.lib
libboost_system-vc110-sgd-1_51.lib
I then created a new Win32 DLL project and added the proper include/lib directories.
But when I try to compile, I get the following output:
LNK1104: cannot open file 'libboost_filesystem-vc110-mt-gd-1_51.lib
But this file does not exist because (afaik) it IS NOT the static version of the library...
Which is odd because I never asked to link against the DLL version anywhere in my project!
So why is my project complaining about a library which I never asked to use?
Do the boost headers automatically try to link against their corresponding libs?
Is there some sort of preprocessor flag I should be setting to tell boost I want to use the static, single-threaded version of boost::filesystem?
UPDATE:
I have been informed in the comments that boost does in fact try to auto-link for compilers which support it, via <boost/config/auto_link.hpp>...
After several attempts to properly configure these headers to use the static, /MDd (debug) & /MD (release) versions of boost, I am still getting this error.
So if anyone could tell me how to properly configure OR disable this feature, I will mark it as the answer.
Also, am I correct in assuming that libboost_filesystem-vc110-s-1_51.lib and libboost_filesystem-vc110-sgd-1_51.lib are the proper /MD and /MDd libs?
Thanks!
To disable auto-link you need to define BOOST_ALL_NO_LIB. From the boost documentation:
// BOOST_ALL_NO_LIB: Tells the config system not to automatically select
// which libraries to link against.
// Normally if a compiler supports #pragma lib, then the correct library
// build variant will be automatically selected and linked against,
// simply by the act of including one of that library's headers.
// This macro turns that feature off.
But don't do that - it will not solve your problem. Auto-link is usually right, i.e. you are either linking to the wrong libraries or you have incorrectly configured your preprocessor macros. If linker wants to link to the shared libraries I would guess that you defined BOOST_ALL_DYN_LINK or BOOST_FILE_SYSTEM_DYN_LINK and BOOST_SYSTEM_DYN_LINK. Remove it and it should link just fine.

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 autolinks libraries which are not built by Boost, but the intended ones are built

I am developing a Math application which can be extended by writing python scripts.
I am using Qt 4.6.3 (built as static library, debug and release versions) and Boost 1.43.0 (built as static library, runtime-link also set to static, multi-threaded version, debug and release). Everything is built with MSVC++2008. Boost built the following libraries:
libboost_python-vc90-mt-s-1_43.lib
libboost_python-vc90-mt-s.lib
libboost_python-vc90-mt-sgd-1_43.lib
libboost_python-vc90-mt-sgd.lib
My project compiles, but gives the following error during the linking phase:
1>Linking...
1>LINK : fatal error LNK1104: cannot open file 'boost_python-vc90-mt-gd-1_43.lib'
Why is it not selecting one of my compiled libraries?
I think the s in the library names stands for static, but then the auto-linking feature seems to select a dynamic library, and I want it all linked statically in one executable.
The same happens with the regex library: I have the same 4 regex libraries compiled and a quick test shows this linking error:
1>LINK : fatal error LNK1104: cannot open file 'libboost_regex-vc90-mt-gd-1_43.lib'
What to do?
You can define BOOST_ALL_NO_LIB. This prevents automatic linking of boost libraries and you must then link the required boost libs manually.
If 's' stands indeed for static (I don't know all those modifiers by heart), define the BOOST_ALL_DYN_LINK symbol while compiling (add it to the command line options). It tells boost to link to the DLL libraries. Alternatively, compile/install static boost libraries.
The problem is fixed, during the compilation of the boost libraries, I selected the link=static option. Which creates static libraries. I also selected runtime-link=static option, and this was wrong!
The solution for this problem was compiling boost with runtime-link=shared. Now some extra libraries are added, with the correct filenames, so the linker can find them. At first the compiler still searches for the dll library (boost_python-vc90-mt-gd-1_43.lib, instead of libboost_python-vc90-mt-gd-1_43.lib), everything else from boost links automatically to a static library, but because boost.python has a different auto-linkage set up, when you provide BOOST_PYTHON_STATIC_LIB, it finally links to the right library and it works!