How to deploy boost library? - c++

I have used Boost library (particularly, Boost filesystem) for my project in Visual Studio C++ (9.0 version). This Boost library is installed in C drive. My project is already finished, therefore, I have corresponding Debug and Release.
Now, I want to include particular DLLs of Boost filesystem to Debug and Release, so my first question is which DLLs do I need to copy? It shows many DLLs for filesystem. Ones which I tried are "boost_filesystem-vc90-mt-1_40.dll" and "boost_filesystem-vc90-mt-gd-1_40.dll". Since, I got an idea from the "vc90", I think it means for Visual Studio 9.0?
Second question, even if I don't include these Boost filesystem DLLs to Debug or Release, my EXE file of the project is still working? Can anyone please explain why is this happening? I tried to check if I have Boost Library path somehow in my Environment Variables, but, unfortunately I could not find them there. Thanks a lot.
P.S.: I am a beginner in both C++ and Boost. And, another library that I am using is OpenCV, for which I already copied corresponding DLLs (core, highgui and imgproc) to Debug and Release and this one is working perfectly.

You have 2 options:
a. Deploy Boost DLLs together with your binary. Answering your question - of course if your project depends on Boost, the libraries are required at runtime, your binary will not start without them.
If you deploy Release configuration of your project, then you need boost_filesystem-vc90-mt-1_40.dll library. In general you can just see all the dependencies of your binary using Dependency Walker tool.
b. Link Boost libraries statically, in this case your binary will not have runtime dependency on Boost DLLs, so you don't have to deploy them

Related

How to setup complex project with Visual Studio 2022?

I have project that I was developing for years in Linux.
It depends on MKL, libxml++, GSL and armadillo library.
Its installation structure is done in CMake and project is formed by building a shared library and couple of executables that link to it. There are about 20 classes in the library.
Project structure is:
--src
--executable1.cpp
--executable2.cpp
--mysharedlib
--class1.h
--class1.cpp
--...
My question is how to install and run this code in Visual Studio in Windows.
I never used VS before and am still going through tutorials. I managed to run my code by installing Ubuntu on WSL, but I I'd like a VS solution as it'd be handy to pass to user not familiar with Linux.
I tried opening the project directory with VS, hoping CMAKE would do all the magic, but expectedly it cannot locate the dependent libraries, so I am now going through web looking how to integrate each to VS. I managed to find armadillo and mkl guide, but I am lost on how to link these libraries to my project codes and whether I should abandon its current cmake setup and start building the code structure differently in VS.
Any links to useful VS tutorials and advices how to this are greatly appreciated.
VS does have support for CMake, although I have no idea how well VS integrates CMake. If you're not set on using VS, you might want to look into an IDE that uses CMake at it's core, Clion comes to mind. That being said, when coming from Linux you don't have the (initial) luxury of simply installing all the dependencies via a preinstalled package manager.
In order for CMake to find your dependencies (assuming you've configured them by using find_package()) you should add the sources of your dependencies to your project in a thirdparty folder (name is up to you) and add these dependencies using add_subdirectory() instead. This will compile all your dependencies from source, so you might have to configure these dependencies yourself (look into the documentation of your dependencies on how to build them from source).
Another way is to use a package manager that is available on Windows to download, compile and provide your dependencies to your build tools. vcpkg comes to mind, claiming to integrate well with CMake by providing a toolchain file that you can pass to CMake when building your project. You might even be able to configure VS to automatically pass this toolchain to CMake whenever it's invoked.
From personal experience, there is no need to convert an existing project to the VS project structure. There's plenty of available solutions and tools available on Windows to work with CMake projects. Going with the cross-platform approach should be preferred unless you're only targeting Windows, using VS to it's fullest then might give you some additional quality of life.
If you have more specific questions regarding this, I suggest that you update your original post or to create separate, specific questions regarding the processes involved in setting up an existing CMake project on Windows.

How do I setup a Codeblocks project on Windows 10 to compile and link a static SFML project?

My advance appologies for being hopeless at Windows development. I am by no means a Windows developer and my understanding of how to write, compile and link C++ code on a Windows system is limited to say the least.
I am having difficulty trying to compile and link a SFML project on a Windows 10 system with the CodeBlocks IDE.
I am trying to link this project with static linking, not dynamic linking. Again I have virtually no idea how the two different methods work in detail, I just know that if I ship a static linked binary to another Windows 10 user it is much more likely to "just work" on their system.
List of things I did:
Downloaded the latest version of CodeBlocks with MINGW integration.
Installed, default options
Downloaded the latest version of SFML (32bit MINGW version)
Extracted the zip file (SFML) to my home directory
Created a new codeblocks project (console application) and followed the instructions to set the compiler and linker options
https://www.sfml-dev.org/tutorials/2.5/start-cb.php
It works fine for dynamic linking, but requires me to copy the .dll files to the same dir as the produced executable file (produced from compilation of my C++ code).
I tried to change to static linking, changing the names of the linker libs with the -s or -s-d suffix, and adding the define SMFL_STATIC option to global (release and debug) options. I also added the opengl32, freetype, winmm and gdi32 link libs, before their respective sfml link libs.
When trying to compile I get the following linker errors
cannot find -lfreetype
cannot find -lsfml-graphics-s-d
cannot find -lsfml-window-s-d
cannot find -lsfml-system-s-d
in Release mode, similar errors are produced.
What am I doing wrong?
My hunch would be that you either have the wrong compiler (see below) or you haven't defined the library directory as mentioned in the linked tutorial.
There are four common things to consider when using SFML (and essentially any other C++ library) on Windows.
Compiler versions have to fully match
Make sure to not mix x86 and x64
Settings need to be specified for the correct configuration
When linking libraries statically, you also need to link the dependencies
Compiler versions have to fully match
Since C++ doesn't have a standardized ABI, the generated libraries will never be reusable between compilers. Yes, sometimes "it works", but it can break at any point and there's no guarantee.
We strongly recommend to either use the compilers linked on the SFML Download page or build SFML from source with your current compiler.
If you got the latest stable Code::Blocks version with MinGW as stated, you should also be able to get a snapshot build of SFML, which should be using the same compiler.
Note: One exception to this rule is Visual Studio, where VS 2017 binaries are compatible with VS 2019 (and maybe VS 2022?).
Make sure to not mix x86 and x64
When you download a 32-bits (x86) version of SFML, you also need a 32-bits version of your compiler. When you download a 64-bits (x64) version of SFML, you also need a 64-bits version of your compiler.
Make sure you double check your compiler configuration that you've selected the correct bit-ness.
Note: For Visual Studio you need to select the correct compiler architecture in the IDE, usually positioned right next to the run button.
Settings need to be specified for the correct configuration
Project configurations are usually spread across the matrix built from the types:
Debug / Release / All
x86 / x64 (for VS)
Make sure when you add the settings for library paths and include paths that it's not just set for debug or release and ends up missing in either or the other configuration.
Also make sure you're not setting up debug libraries (with the -d suffix) in release mode or release libraries (without any suffix) in debug mode.
When linking libraries statically, you also need to link the dependencies
The SFML static libraries don't contain any symbols of any of its dependencies, that means, in your final application you have to link static SFML and all its dependencies.
As a short summary you can think of static libraries like an archive of object files. These object files will directly be linking into your application, like you link your own source file object files. As such, the SFML static libraries only contain object files of SFML itself and not of other libraries as well.
Troubleshooting
If nothing seems to help, then you should enable verbose compiler & linker output, that we you see exactly which commands are invoked and one can quickly spot the missing statements.

How on earth do i use Boost?

I'm reasonably new to C++, and I was going to mess around with threading for my Tamagochi game, however it seems that everything says I should get Boost for that.
So my question is, how on earth do I install it?
I've found ways of using it by doing the whole "Add the path in the properties" thing. And that works, however I'm guessing that if I use that way, I wont be able to compile and release it afterwards?
I also tried using BlueGo from vertexwahn.de.
but I have no idea what it actually does. I get the whole "It compiles the libraries for you" thing but, how do I use them then?
Should they work from within VS2012 without further tweaking, or do I still need to add in the path's in properties?
I just want to use the threading from Boost, and then build the project and send to a friend.
I was going to mess around with threading...
If my reading of MSDN is correct, Visual Studio 2012 appears to support the new threading features of C++ 11. With this in mind, you don't need to install Boost. You can just use the standard <thread> header instead.
Some boost modules have to be built.
For Windows, you have to use bjam.exe to build your libraries.
And bootstrap.bat will build you bjam.exe
From your unzipped boost directory :
bootstrap.bat
bjam.exe release debug toolset=msvc address-model=32 --build-type=complete
bjam.exe release debug toolset=msvc address-model=64 --build-type=complete
And check your stage/lib for *.lib, *.dll
(You may have to clean your stage/lib directory between two bjam commands)
Then, add include directory and library directory to your VS project.
Needed libraries will be automatically linked (you do not have to tell VS to use boost thread for example), boost use pragma to find out what is needed. It doesn't work for Linux though.
As previously stated, VS2012 already handle threads, but boost is much more than that and I strongly recommand using it for whatever you want to code.
With asio from boost, you can even make thread pool : see recipe
download boost
compile boost (go to the boost directory, call
bootstrap and after this is finished call b2)
decide which part of boost to use
add the main boost directory to your include path and the lib (with default it is in stage - just search for the lib files) directory to your linker path
make sure that you link boost thread dynamically (there may be problems if you link statically)
program

Build boost.Log on Windows 7

I recently downloaded http://boost-log.sourceforge.net/libs/log/doc/html/index.html but I can't seem to find out how to build it. The rest of my boost lib was installed by using the installer, so all I did was selecting the files I wanted to include.
So how do I build Logs? Building for windows is completely new to me and I would really appreciate any help!
EDIT
Merge boost.log in the boost directory structure first.
Did you build boost ? If not, you have to go to your boost directory, run boostrap.sh and then run b2.exe. That will build all boost libraries.
Since you are on Windows, boost supports automatic linking, i.e. you just include the header files and the required libraries will be linked automatically when building your project from Visual Studio.

How to include boost::filesystem into a VS2010 project without adding a dependency on bjam?

According to this answer, the intended way to include non-header-only parts of Boost into a Visual Studio 2010 project require the use of bjam to build the correct libraries.
What is unclear to me is whether this is a one-time-only thing, where I just check in the lib files produced by bjam, or whether anyone who wants to build my project will from now on require not only Visual Studio but also bjam.
The project only targets Windows 32-bits, because it builds a plugin for a program that's only available in this configuration, and only needs to support the statically-linked multi-threaded CRT.
(For the record, if I just include the relevant .cpp files into the build, the compile stage succeeds, but at link stage I get a missing library error, which is apparently caused by the "auto-link" feature. Perhaps I should just disable auto-linking, if it's possible?)
You don't need bjam. Like yasouser answered, you can download the installer from boost pro, the downsides being that
you need to register though that's quick and easy
it's usually/sometimes a release or two behind the latest boost release.
What is unclear to me is whether this is a one-time-only thing, where I just check in the lib files produced by bjam, or whether anyone who wants to build my project will from now on require not only Visual Studio but also bjam.
It is a one time thing per machine. Once you have the boost binaries you don't need bjam anymore. The nice thing about the installer is that you can install some selected versions of the boost libraries + the headers (You can select VS version, single-threaded, static/dynamic, etc. on a per library basis e.g. thread, system, etc.) and then at a later point you can just run the installer again and add other binaries.
So if you're auto-linking and are missing a specific lib, just run the installer again.
FYI, you can disable boost's autolinking option by defining BOOST_ALL_NO_LIB and then manually linking in the lib versions you want.
Some of the boost libraries require you to build them as static or shared libraries and link them in your project. Either you can download the source and build it for yourself using bjam or you can install the pre-built binaries from here.
Yes this is a one time install (if you are installing from pre-built binaries or built by yourself). And those building your project will also need to do the boost install once for them to be able to build your project.
if I just include the relevant .cpp
files into the build
Direct including cpp files has many drawbacks. The only reason of borrowing .cpp files I can imagine is to allow build the project on other PCs without installing boost there. But I think it can be solved by distributing particular boost .lib files as well.