Boost C++ Libraries in action
How to setup boost libraries for code:: blocks?
PreRequisite
- Need to setup code::blocks and compiler.
- Download boost libraries setup file.
- GCC (optional).
To set up the boost libraries there are two different ways
- To download libraries. (Need to Compile )
- To download prebuilt binaries. (Compiled libraries)
Note:- I prefer Compiled libraries (Method 2).
Method 1 (Header Only)
Procedure:-
- Download either the zip or the 7zip package of boost. Extract the contents to extract_dir.
- Open Command Prompt (cmd.exe) and navigate to extract_dir. cd extract_dir
- Build the boost build system by entering “bootstrap.bat mingw” or “bootstrap.bat gcc”. Don’t forget, for the Boost libraries needing additional compilation, you need to run the boostrap.bat and b2.exe commands via the Boost root directory.
- Open the file extract_dir\project-config.jam in Notepad and change the word msvc to GCC.
- Back in the Command Prompt window, run “b2.exe”.
Method 2 (Compiled libraries)
Using pre-built binaries
Procedure:-
- download the prebuilt binaries.
- install it.
Hope you're done with either of the two methods.
Linking the libraries
Now to link them in code::blocks
- Run code::blocks
- Go to setting in the dropdown menu
- then click on the compiler option in the dropdown list
- Navigate to Linker settings then click on add.
- Select the Search Directories tab.
- select the Compiler tab.
- Set the location of the Boost root directory
- Select the Linker tab and set the location of the library files
- In the Linker Setting tab add the necessary library names. eg:- boost_X_XY_X
5.After clicking on add Navigate to boost libraries.
The default path is C:\Program Files\boost_X_XY_X\lib64-msvc-14.2
6. Then use CTRL + A to select all the files then click open.
Close and reopen code::blocks.
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
using namespace std;
int128_t boost_product(long long A, long long B)
{
int128_t ans = (int128_t) A * B;
return ans;
}
int main()
{
long long first = 98745636214564698;
long long second=7459874565236544789;
cout << “Product of “<< first << “ * “
<< second << “ = \n”
<< boost_product(first,second) ;
return 0;
}
Build, Compile, and run the code.
Post any queries in the below comment section.