Boost Logging出现LNK1104错误的原因及Visual Studio环境下的解决方法
Hey there, let's work through your Boost Log linking issue step by step!
Absolutely. The LNK1104 error here stems directly from the linker being unable to find the matching precompiled Boost.Log library for your project's configuration. Unlike many header-only Boost modules, Boost.Log requires compiled binaries. The NuGet package you installed might not include libraries for your exact project setup (like x64 Debug with multi-threaded debug runtime), so compiling the library yourself to match your config is a valid and reliable fix.
If you want to build the library tailored to your VS2017 project, follow these steps:
Grab the Boost source code
Download the Boost 1.76 source package from the official site, then extract it to a local folder (e.g.,C:\boost_1_76_0).Launch the VS Developer Command Prompt
Open VS2017, go to Tools > Command Line > Developer Command Prompt (or search for "VS 2017 Developer Command Prompt for x64" in the Start Menu—pick the one matching your project's target platform, x64 in your case).Initialize Boost's build tool
Navigate to your extracted Boost root directory in the command prompt, then run:bootstrap.batThis generates
b2.exe, Boost's build utility.Compile the Boost.Log module
Run theb2command with parameters matching your project's configuration (the error message shows you need themt-gdvariant—multi-threaded, debug, dynamic runtime):b2 toolset=msvc-14.1 address-model=64 variant=debug link=shared threading=multi --with-logLet's break down those flags:
toolset=msvc-14.1: Targets VS2017's compiler (vc141)address-model=64: Builds for x64 architecture (use32for x86)variant=debug: Compiles the debug version (swap toreleasefor release builds)link=shared: Builds dynamic libraries (usestaticfor static linking)--with-log: Only compiles the Boost.Log module (way faster than building all of Boost)
Once done, your compiled libraries will be in
boost_1_76_0\stage\lib.Point your VS project to the compiled libraries
Right-click your project in VS2017 > Properties:- Go to VC++ Directories > Library Directories and add the path to your
stage\libfolder (e.g.,C:\boost_1_76_0\stage\lib) - Go to Linker > Input > Additional Dependencies and add the exact library name from your error:
libboost_log-vc141-mt-gd-x64-1_76.lib
- Go to VC++ Directories > Library Directories and add the path to your
If you'd rather avoid compiling from source, try these options:
- Verify NuGet configuration matching
Double-check that your project's settings align with the NuGet package's libraries:- Platform Toolset should be
v141(VS2017 default) - Target Platform is
x64 - C/C++ > Code Generation > Runtime Library is set to Multi-threaded Debug DLL (/MDd)
If the NuGet package doesn't have libraries for this exact config, try reinstalling a Boost.Log NuGet package that explicitly supports vc141, x64, and debug builds.
- Platform Toolset should be
- Use a more comprehensive NuGet package
Search NuGet.org for "Boost.Log"—some third-party packages include a wider range of precompiled configurations for VS2017. Pick one that matches your project's setup and install it.
内容的提问来源于stack exchange,提问作者Minh To Quang

