Building with Boost on Windows 10 using CMake
Recently I begun work on porting mcidle to C++. Since I was going to use Boost I had to link with it during my build process. Visual Studio makes this somewhat unintuitive.
For starters, it goes without saying on Windows 10 you definitely need Visual Studio for the compiler toolset to get a build system working (probably can work with MinGW makefiles too but I haven’t tried it).
If you try to create a project in Visual Studio 2019 and select a “CMake Project” you will NEVER get boost to link with Visual Studio and keep on receiving a single LINK1104
error linking with boost libs. I made sure that all the libs were definitely set, even going so far as to setting BOOST_LIBRARYDIR
. And to this day I don’t even really know why because I couldn’t find the directory that it was trying to link to even though it definitely was able to find my Boost directory using FindBoost
.
Unlike generating a project from a solution using CMake, the VS project you get is just a build file and it tries to compile a binary without generating a solution first so you can’t change how it links. This is the fundamental issue with Microsoft’s notion of “just building a CMake Project” using our pre-generated CMake Project thingy. You literally shouldn’t be doing this ever on Windows because it’s not useful.
It turns out the solution is to use the CMake binary in your command line of choice and ask it to generate a solution file for Visual Studio 2019 as opposed to using Visual Studio 2019 to generate a CMake project and then build from there. You’ll still get a linker error with Visual Studio, but because you have a solution file you can manually add the header/libs needed by right clicking the project solution.
My theory is this problem stems from auto linking but I’m not really sure. 6.1 in this guide is basically what I ended up doing.
Back