Is Visual Studio adding dependencies from out of nowhere? - c++

I'm having a problem building a windows C++ project with a specially modified version of the boost library. I'm not using bjam, but instead have a custom project using cmake to manage building a small sub-set of the boost libraries. Everything seems to compile fine, but then I get a linking error for an entity that was never mentioned in cmake or any of the source files:
2>LINK : fatal error LNK1104: cannot open file 'libboost_thread-vc100-mt-gd-1_54.lib'
I searched for this string in my build folder using 'findstr', and found it mentioned in thread.obj in this context:
/DEFAULTLIB:liboobst_thread-vc100-mt-gd-1_54.lib
My question is: where did this /DEFAULTLIB tag come from and how do I prevent it? I turned on explicit compile and linking flags ("Suppress Startup Banner"=No) and it is not mentioned anywhere during the build process.
Edit:
Per commenters, this is part of the auto-linking feature in boost, which can be disabled with the BOOST_ALL_NO_LIB definition. Described here.

Per the commenters, this is part of the auto-linking feature in boost, which can be disabled with the BOOST_ALL_NO_LIB definition. Described here.

Related

mlpack include file errors

Recently I am about to learn mlpack. Today I have successfully built the solution from mlpack source code, but when I newly create a project I get the following error in the header file. I would like to know what is wrong and how to fix it.
errors
In the screenshot, the algorithm.hpp is under the build folder and its absolute path is D:\MLPack\mlpack\build\include\mlpack\core\std_backport\algorithm.hpp. The source code in the new project is just a copy from https://www.mlpack.org/.
The screenshot below shows some of the files generated after building solution of mlpack.sln.
generated libs
The versions of other libraries to help build the mlpack are :
Armadillo 10.8.0 (at least 9.800)
Boost (math_c99, spirit) 1.78.0 (at least 1.58.0, and I have added this version string in CMakeLists.txt before building mlpack)
CMake 3.20 (at least 3.6)
ensmallen 2.18.1 (at least 2.10.0)
cereal 1.3.0 (at least 1.1.2)
openBLAS 0.24.1
The configurations of my new project are shown below.
additional include directories
additional dependencies
post-build event
And I have also disabled "Conformance Mode".
disabled conformance mode
The entire building and using process refer to https://www.mlpack.org/doc/stable/doxygen/build_windows.html and https://www.mlpack.org/doc/mlpack-3.4.2/doxygen/sample_ml_app.html.
I finally found out that this problem seems to be related to the version of the source code. I should not use the latest version of the source code from https://github.com/mlpack/mlpack, but the source code corresponding to the latest stable version. After I replaced the include directory with the include directory corresponding to the officially released windows installation package, no error was reported during the building of the solution in my new project, so I got the expected result.
the result
This incident taught me a lesson that I should use the stable rather than the latest version of the source code when doing CMake in the future.

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 .

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)

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!