1

I am trying to use boost libraries in VSCode (using Cmake & vcpkg) but can't seem to figure out what's wrong. I installed Boost in vcpkg. Here are the error messages.

main.cpp

#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;
}

setting.json

{
    "C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
    "cmake.configureSettings": {
        "CMAKE_TOOLCHAIN_FILE": "C:/vcpkg/scripts/buildsystems/vcpkg.cmake"
    }
}

CmakeLists.txt

cmake_minimum_required(VERSION 3.0.0)
project(demo VERSION 0.1.0)

include(CTest)
enable_testing()

add_executable(demo main.cpp)

set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)

Errors:

main.cpp:1:10: fatal error: boost/multiprecision/cpp_int.hpp: No such file or directory
    1 | #include <boost/multiprecision/cpp_int.hpp>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

Maybe I am missing something. Please help.Thank you!

Dinh Minh Luu
  • 71
  • 4
  • 7
  • 1
    `find_package(Boost COMPONENTS system log REQUIRED);` – Ghasem Ramezani Aug 16 '21 at 05:49
  • 2
    Stack Overflow discourages using an **image** for a code and an error message. Instead, copy-paste them as a **text** into the question post and format accordingly (as a code). See also [ask]. – Tsyvarev Aug 16 '21 at 06:32
  • @GhasemRamezani It shows error: "[cmake] Could NOT find Boost (missing: Boost_INCLUDE_DIR system log)" – Dinh Minh Luu Aug 16 '21 at 11:10
  • There is nothing in your build files telling CMake about your dependency on Boost. – Alex Reinking Aug 16 '21 at 12:13
  • @AlexReinking how can I fix the issue? In vcpkg guidelines, they say something about using find_package but I don't know to implement that. – Dinh Minh Luu Aug 16 '21 at 12:40
  • Did you read the documentation? https://cmake.org/cmake/help/latest/module/FindBoost.html#examples (see "Find Boost libraries and use imported targets") https://cmake.org/cmake/help/latest/guide/importing-exporting/index.html#importing-libraries – Alex Reinking Aug 16 '21 at 12:43
  • Does this answer your question? [How to link C++ program with Boost using CMake](https://stackoverflow.com/questions/3897839/how-to-link-c-program-with-boost-using-cmake) (see [oLen](https://stackoverflow.com/a/43885372/2137996)'s answer) – Alex Reinking Aug 16 '21 at 12:44
  • @AlexReinking I tried but it keeps saying "Could NOT find Boost (missing: Boost_INCLUDE_DIR) ". – Dinh Minh Luu Aug 16 '21 at 13:18
  • @AlexReinking the boost libraries folder in vcpkg has a different name. – Dinh Minh Luu Aug 16 '21 at 13:30

0 Answers0