0

I'm using Visual Studio to compile a C++ project using CMake as the build system.

Furthermore I'm linking against the Boost library. The output executable however will not run if the following Boost DLLs are not found in the PATH environment variable: boost_filesystem-vc141-mt-x64-1_69.dll and boost_iostreams-vc141-mt-x64-1_69.dll.

According to the documentation, I tried using the /MT ("Causes the application to use the multithread, static version of the run-time library") and also the /MD ("Causes the application to use the multithread-specific and DLL-specific version of the run-time library") compilation flag but besides affecting the file size, the DLL dependence on Boost did not change.

I also specified the following CMake variables:

set(BOOST_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)

This did not force static linking against the Boost libraries either. I want to generate an executable which does not dynamically depend on Boost but only on the core C++ runtime libraries so any other machine can run it without shipping Boost or any Boost DLLs. It is totally fine if the file size increases quite a bit.

Adding the following preprocessor define to main.cpp does not work either:

#define BOOST_ALL_NO_LIB 1

How can I really build the standalone executable?

BullyWiiPlaza
  • 17,329
  • 10
  • 113
  • 185
  • Do you have static libs installed and are you linking against them? – Thomas Sablik Dec 10 '18 at 22:35
  • @ThomasSablik: I have libraries named like `boost_iostreams-vc141-mt-gd-x64-1_69.lib` and `boost_iostreams-vc141-mt-x64-1_69.lib`. Those are from the precompiled libraries download: https://sourceforge.net/projects/boost/files/boost-binaries I assume they are the dynamic ones (https://stackoverflow.com/questions/4619764) so I still have to compile static ones and then it should work as expected? – BullyWiiPlaza Dec 10 '18 at 22:40
  • Yes, looks like dynamic libs. Try it with static libs. – Thomas Sablik Dec 10 '18 at 22:50

1 Answers1

0

So it turns out that I just misspelled setting Boost to use the static libraries:

set(Boost_USE_STATIC_LIBS ON)

CMake variables are case-sensitive so spelling out Boost with capital letters does not work.

The precompiled Windows binaries already contain everything needed so compiling yourself is not necessary if you just want to link against the static libraries.

BullyWiiPlaza
  • 17,329
  • 10
  • 113
  • 185